1From cb1b8b8516ade9add9f63fa0e39eaa3bc7034828 Mon Sep 17 00:00:00 2001 2From: David Kilzer <ddkilzer@apple.com> 3Date: Mon, 10 Apr 2023 13:06:18 -0700 4Subject: [PATCH] xmlValidatePopElement() can return invalid value (-1) 5 6Covered by: test/VC/ElementValid5 7 8This only affects XML Reader API with LIBXML_REGEXP_ENABLED and 9LIBXML_VALID_ENABLED turned on. 10 11* result/VC/ElementValid5.rdr: 12- Update result to add missing error message. 13 14* python/tests/reader2.py: 15* result/VC/ElementValid6.rdr: 16* result/VC/ElementValid7.rdr: 17* result/valid/781333.xml.err.rdr: 18- Update result to fix grammar issue. 19 20* valid.c: 21(xmlValidatePopElement): 22- Check return value of xmlRegExecPushString() to handle -1, and 23 assign 'ret = 0;' to return 0 from xmlValidatePopElement(). 24 This change affects xmlTextReaderValidatePop() from 25 xmlreader.c. 26- Fix grammar of error message by changing 'child' to 27 'children'. 28 29Reference:https://github.com/GNOME/libxml2/commit/cb1b8b8516ade9add9f63fa0e39eaa3bc7034828 30Conflict:python/tests/reader2.py 31 32--- 33 python/tests/reader2.py | 2 +- 34 result/VC/ElementValid5.rdr | 3 +++ 35 result/VC/ElementValid6.rdr | 2 +- 36 result/VC/ElementValid7.rdr | 2 +- 37 result/valid/781333.xml.err.rdr | 2 +- 38 valid.c | 5 +++-- 39 6 files changed, 10 insertions(+), 6 deletions(-) 40 41diff --git a/python/tests/reader2.py b/python/tests/reader2.py 42index b50180d..b581674 100755 43--- a/python/tests/reader2.py 44+++ b/python/tests/reader2.py 45@@ -39,7 +39,7 @@ value 46 """../../test/valid/781333.xml:4: element a: validity error : Element a content does not follow the DTD, expecting ( ..., got 47 <a/> 48 ^ 49-../../test/valid/781333.xml:5: element a: validity error : Element a content does not follow the DTD, Expecting more child 50+../../test/valid/781333.xml:5: element a: validity error : Element a content does not follow the DTD, Expecting more children 51 52 ^ 53 """, 54diff --git a/result/VC/ElementValid5.rdr b/result/VC/ElementValid5.rdr 55index 899d759..91eef9c 100644 56--- a/result/VC/ElementValid5.rdr 57+++ b/result/VC/ElementValid5.rdr 58@@ -4,3 +4,6 @@ 59 ./test/VC/ElementValid5:8: element doc: validity error : Element doc content does not follow the DTD, Misplaced b 60 61 ^ 62+./test/VC/ElementValid5:8: element doc: validity error : Element doc content does not follow the DTD, Expecting more children 63+ 64+^ 65diff --git a/result/VC/ElementValid6.rdr b/result/VC/ElementValid6.rdr 66index aeafd6b..3b51d1a 100644 67--- a/result/VC/ElementValid6.rdr 68+++ b/result/VC/ElementValid6.rdr 69@@ -1,6 +1,6 @@ 70 ./test/VC/ElementValid6:7: element doc: validity error : Element doc content does not follow the DTD, expecting (a , b? , c+)?, got (a b) 71 <doc><a/><b>lacks c</b></doc> 72 ^ 73-./test/VC/ElementValid6:8: element doc: validity error : Element doc content does not follow the DTD, Expecting more child 74+./test/VC/ElementValid6:8: element doc: validity error : Element doc content does not follow the DTD, Expecting more children 75 76 ^ 77diff --git a/result/VC/ElementValid7.rdr b/result/VC/ElementValid7.rdr 78index f001fd2..ecafd1d 100644 79--- a/result/VC/ElementValid7.rdr 80+++ b/result/VC/ElementValid7.rdr 81@@ -1,6 +1,6 @@ 82 ./test/VC/ElementValid7:7: element doc: validity error : Element doc content does not follow the DTD, expecting ((a | b)* , c+ , a , b? , c , a?), got (a b a c c a) 83 <doc><a/><b/><a/><c/><c/><a/></doc> 84 ^ 85-./test/VC/ElementValid7:8: element doc: validity error : Element doc content does not follow the DTD, Expecting more child 86+./test/VC/ElementValid7:8: element doc: validity error : Element doc content does not follow the DTD, Expecting more children 87 88 ^ 89diff --git a/result/valid/781333.xml.err.rdr b/result/valid/781333.xml.err.rdr 90index 5ff5699..dd9df08 100644 91--- a/result/valid/781333.xml.err.rdr 92+++ b/result/valid/781333.xml.err.rdr 93@@ -1,6 +1,6 @@ 94 ./test/valid/781333.xml:4: element a: validity error : Element a content does not follow the DTD, expecting ( ..., got 95 <a/> 96 ^ 97-./test/valid/781333.xml:5: element a: validity error : Element a content does not follow the DTD, Expecting more child 98+./test/valid/781333.xml:5: element a: validity error : Element a content does not follow the DTD, Expecting more children 99 100 ^ 101diff --git a/valid.c b/valid.c 102index 3c0a869..92aaedb 100644 103--- a/valid.c 104+++ b/valid.c 105@@ -6012,11 +6012,12 @@ xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED, 106 if (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT) { 107 if (state->exec != NULL) { 108 ret = xmlRegExecPushString(state->exec, NULL, NULL); 109- if (ret == 0) { 110+ if (ret <= 0) { 111 xmlErrValidNode(ctxt, state->node, 112 XML_DTD_CONTENT_MODEL, 113- "Element %s content does not follow the DTD, Expecting more child\n", 114+ "Element %s content does not follow the DTD, Expecting more children\n", 115 state->node->name, NULL,NULL); 116+ ret = 0; 117 } else { 118 /* 119 * previous validation errors should not generate 120-- 1212.27.0 122 123