1From 003d0baef83a3c694fba6f194cfc8c14bc035082 Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Mon, 21 Nov 2022 22:07:11 +0100 4Subject: [PATCH 23/28] parser: Restore parser state in xmlParseCDSect 5 6Fixes #441. 7 8Reference: https://github.com/GNOME/libxml2/commit/94ca36c2c48ad3857175ea66a373e51e67b98f00 9Conflict: parser.c:<xmlParseCDSect> 10--- 11 parser.c | 25 +++++++++++-------------- 12 1 file changed, 11 insertions(+), 14 deletions(-) 13 14diff --git a/parser.c b/parser.c 15index 6e55838..4360479 100644 16--- a/parser.c 17+++ b/parser.c 18@@ -9788,22 +9788,20 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { 19 r = CUR_CHAR(rl); 20 if (!IS_CHAR(r)) { 21 xmlFatalErr(ctxt, XML_ERR_CDATA_NOT_FINISHED, NULL); 22- ctxt->instate = XML_PARSER_CONTENT; 23- return; 24+ goto out; 25 } 26 NEXTL(rl); 27 s = CUR_CHAR(sl); 28 if (!IS_CHAR(s)) { 29 xmlFatalErr(ctxt, XML_ERR_CDATA_NOT_FINISHED, NULL); 30- ctxt->instate = XML_PARSER_CONTENT; 31- return; 32+ goto out; 33 } 34 NEXTL(sl); 35 cur = CUR_CHAR(l); 36 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); 37 if (buf == NULL) { 38 xmlErrMemory(ctxt, NULL); 39- return; 40+ goto out; 41 } 42 while (IS_CHAR(cur) && 43 ((r != ']') || (s != ']') || (cur != '>'))) { 44@@ -9812,9 +9810,8 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { 45 46 tmp = (xmlChar *) xmlRealloc(buf, size * 2 * sizeof(xmlChar)); 47 if (tmp == NULL) { 48- xmlFree(buf); 49 xmlErrMemory(ctxt, NULL); 50- return; 51+ goto out; 52 } 53 buf = tmp; 54 size *= 2; 55@@ -9829,8 +9826,7 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { 56 SHRINK; 57 GROW; 58 if (ctxt->instate == XML_PARSER_EOF) { 59- xmlFree(buf); 60- return; 61+ goto out; 62 } 63 count = 0; 64 } 65@@ -9839,17 +9835,14 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { 66 if (len > maxLength) { 67 xmlFatalErrMsg(ctxt, XML_ERR_CDATA_NOT_FINISHED, 68 "CData section too big found\n"); 69- xmlFree(buf); 70- return; 71+ goto out; 72 } 73 } 74 buf[len] = 0; 75- ctxt->instate = XML_PARSER_CONTENT; 76 if (cur != '>') { 77 xmlFatalErrMsgStr(ctxt, XML_ERR_CDATA_NOT_FINISHED, 78 "CData section not finished\n%.50s\n", buf); 79- xmlFree(buf); 80- return; 81+ goto out; 82 } 83 NEXTL(l); 84 85@@ -9862,6 +9855,10 @@ xmlParseCDSect(xmlParserCtxtPtr ctxt) { 86 else if (ctxt->sax->characters != NULL) 87 ctxt->sax->characters(ctxt->userData, buf, len); 88 } 89+ 90+out: 91+ if (ctxt->instate != XML_PARSER_EOF) 92+ ctxt->instate = XML_PARSER_CONTENT; 93 xmlFree(buf); 94 } 95 96-- 972.27.0 98 99