From e6081cb8c8fc1d1f4c6fa4d9873cec49e875576f Mon Sep 17 00:00:00 2001 From: bettermanzzy Date: Fri, 6 Sep 2019 18:44:59 +0800 Subject: [PATCH] fix issue28:libxml2 doesn't correctly raise errors on Occurence based restrictions --- include/libxml/xmlregexp.h | 2 ++ xmlregexp.c | 20 ++++++++++++++++++++ xmlschemas.c | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/include/libxml/xmlregexp.h b/include/libxml/xmlregexp.h index 7009645a..6b55a3e0 100644 --- a/include/libxml/xmlregexp.h +++ b/include/libxml/xmlregexp.h @@ -92,6 +92,8 @@ XMLPUBFUN int XMLCALL const xmlChar *value, const xmlChar *value2, void *data); +XMLPUBFUN int XMLCALL + xmlRegExecPushString3(xmlRegExecCtxtPtr exec); XMLPUBFUN int XMLCALL xmlRegExecNextValues(xmlRegExecCtxtPtr exec, diff --git a/xmlregexp.c b/xmlregexp.c index 9e9c3752..0b9fa6f5 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -4201,6 +4201,26 @@ xmlRegExecPushString2(xmlRegExecCtxtPtr exec, const xmlChar *value, return(ret); } +int +xmlRegExecPushString3(xmlRegExecCtxtPtr exec) { + if (exec == NULL) + return(-1); + if (exec->comp == NULL) + return(-1); + if (exec->status != 0) + return(exec->status); + if ((exec->comp->counters) != NULL) { + if ((exec->comp->counters[((exec->state->nbTransTo - 1)/2)-1].min) >= 0) { + if (((exec->state->nbTransTo - 1)/2)-1 >= 0 ) { + if (exec->comp->counters[((exec->state->nbTransTo - 1)/2)-1].max ==-1) { + return (-1); + } + } + } + } + return (1); +} + /** * xmlRegExecGetValues: * @exec: a regexp execution context diff --git a/xmlschemas.c b/xmlschemas.c index f3d2664b..5e0bcd6a 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -26669,6 +26669,10 @@ xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt) vctxt->inode->localName, vctxt->inode->nsName, vctxt->inode); + if (ret > 0) { + ret = xmlRegExecPushString3(regexCtxt); + } + #ifdef DEBUG_AUTOMATA if (ret < 0) xmlGenericError(xmlGenericErrorContext, -- GitLab