diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2023-01-22 13:09:03 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2023-01-24 11:32:15 +0100 |
commit | 74aa61e0bdc31700eae06635bd92f0a71d7cbb6e (patch) | |
tree | 1ad31320e7f612e04cec114578c970b467a8832e | |
parent | d9a8dab3a3ba980f1efc1366c1b9a3a2434dcabd (diff) | |
download | libxml2-74aa61e0bdc31700eae06635bd92f0a71d7cbb6e.tar.gz |
parser: Halt parser on DTD errors
If we try to continue parsing after an error in the internal or external
subset, entity expansion accounting gets more complicated. Simply halt
the parser.
Found with libFuzzer.
-rw-r--r-- | parser.c | 9 | ||||
-rwxr-xr-x | python/tests/reader2.py | 28 | ||||
-rw-r--r-- | result/errors/754946.xml.ent | 10 | ||||
-rw-r--r-- | result/errors/754946.xml.err | 10 | ||||
-rw-r--r-- | result/errors/754946.xml.str | 7 | ||||
-rw-r--r-- | result/errors/759573-2.xml.ent | 10 | ||||
-rw-r--r-- | result/errors/759573-2.xml.err | 10 | ||||
-rw-r--r-- | result/errors/759573-2.xml.str | 7 | ||||
-rw-r--r-- | result/errors/759573.xml.ent | 10 | ||||
-rw-r--r-- | result/errors/759573.xml.err | 10 | ||||
-rw-r--r-- | result/errors/759573.xml.str | 7 | ||||
-rw-r--r-- | result/errors/content1.xml.ent | 6 | ||||
-rw-r--r-- | result/errors/content1.xml.err | 6 | ||||
-rw-r--r-- | result/errors/content1.xml.str | 3 | ||||
-rw-r--r-- | result/errors10/781205.xml.err | 10 | ||||
-rw-r--r-- | result/errors10/781361.xml.err | 6 | ||||
-rw-r--r-- | result/valid/t8.xml.err | 14 | ||||
-rw-r--r-- | result/valid/t8.xml.err.rdr | 14 | ||||
-rw-r--r-- | result/valid/t8a.xml.err | 14 | ||||
-rw-r--r-- | result/valid/t8a.xml.err.rdr | 14 |
20 files changed, 4 insertions, 201 deletions
@@ -7143,7 +7143,8 @@ xmlParseExternalSubset(xmlParserCtxtPtr ctxt, const xmlChar *ExternalID, xmlParseMarkupDecl(ctxt); } else { xmlFatalErr(ctxt, XML_ERR_EXT_SUBSET_NOT_FINISHED, NULL); - break; + xmlHaltParser(ctxt); + return; } SKIP_BLANKS; } @@ -8481,10 +8482,8 @@ xmlParseInternalSubset(xmlParserCtxtPtr ctxt) { xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR, "xmlParseInternalSubset: error detected in" " Markup declaration\n"); - if (ctxt->inputNr > baseInputNr) - xmlPopInput(ctxt); - else - break; + xmlHaltParser(ctxt); + return; } SKIP_BLANKS; } diff --git a/python/tests/reader2.py b/python/tests/reader2.py index c6bad364..802d848d 100755 --- a/python/tests/reader2.py +++ b/python/tests/reader2.py @@ -69,20 +69,6 @@ Entity: line 1: Entity: line 1: <!ELEMENT root (middle) > ^ -{0}/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -{0}/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ """.format(dir_prefix), 't8a': """{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration @@ -92,20 +78,6 @@ Entity: line 1: Entity: line 1: <!ELEMENT root (middle) > ^ -{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -{0}/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ """.format(dir_prefix), 'xlink': """{0}/xlink.xml:450: element termdef: validity error : ID dt-arc already defined diff --git a/result/errors/754946.xml.ent b/result/errors/754946.xml.ent index a58a8f19..7dc0bb01 100644 --- a/result/errors/754946.xml.ent +++ b/result/errors/754946.xml.ent @@ -5,13 +5,3 @@ Entity: line 1: A<lbbbbbbbbbbbbbbbbbbb_ ^ -./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - - <![ - ^ -./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated - <![ - ^ -./test/errors/754946.xml:4: parser error : Start tag expected, '<' not found - <![ - ^ diff --git a/result/errors/754946.xml.err b/result/errors/754946.xml.err index a58a8f19..7dc0bb01 100644 --- a/result/errors/754946.xml.err +++ b/result/errors/754946.xml.err @@ -5,13 +5,3 @@ Entity: line 1: A<lbbbbbbbbbbbbbbbbbbb_ ^ -./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - - <![ - ^ -./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated - <![ - ^ -./test/errors/754946.xml:4: parser error : Start tag expected, '<' not found - <![ - ^ diff --git a/result/errors/754946.xml.str b/result/errors/754946.xml.str index 7aaf045b..5d6a8b28 100644 --- a/result/errors/754946.xml.str +++ b/result/errors/754946.xml.str @@ -5,11 +5,4 @@ Entity: line 1: A<lbbbbbbbbbbbbbbbbbbb_ ^ -./test/errors/754946.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - - <![ - ^ -./test/errors/754946.xml:4: parser error : DOCTYPE improperly terminated - <![ - ^ ./test/errors/754946.xml : failed to parse diff --git a/result/errors/759573-2.xml.ent b/result/errors/759573-2.xml.ent index 51cb2d95..01c81576 100644 --- a/result/errors/759573-2.xml.ent +++ b/result/errors/759573-2.xml.ent @@ -23,13 +23,3 @@ Entity: line 1: Entity: line 2: <![INCLUDE[ ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%xx; - ^ -./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated -%xx; - ^ -./test/errors/759573-2.xml:6: parser error : Start tag expected, '<' not found -%xx; - ^ diff --git a/result/errors/759573-2.xml.err b/result/errors/759573-2.xml.err index 51cb2d95..01c81576 100644 --- a/result/errors/759573-2.xml.err +++ b/result/errors/759573-2.xml.err @@ -23,13 +23,3 @@ Entity: line 1: Entity: line 2: <![INCLUDE[ ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%xx; - ^ -./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated -%xx; - ^ -./test/errors/759573-2.xml:6: parser error : Start tag expected, '<' not found -%xx; - ^ diff --git a/result/errors/759573-2.xml.str b/result/errors/759573-2.xml.str index 3b7419eb..39f77a66 100644 --- a/result/errors/759573-2.xml.str +++ b/result/errors/759573-2.xml.str @@ -23,11 +23,4 @@ Entity: line 1: Entity: line 2: <![INCLUDE[ ^ -./test/errors/759573-2.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%xx; - ^ -./test/errors/759573-2.xml:6: parser error : DOCTYPE improperly terminated -%xx; - ^ ./test/errors/759573-2.xml : failed to parse diff --git a/result/errors/759573.xml.ent b/result/errors/759573.xml.ent index c3c5a660..74322b66 100644 --- a/result/errors/759573.xml.ent +++ b/result/errors/759573.xml.ent @@ -20,13 +20,3 @@ T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; Entity: line 1: %<![INCLUDE[000%ஸ000%z; ^ -./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ -./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ -./test/errors/759573.xml:1: parser error : Start tag expected, '<' not found -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ diff --git a/result/errors/759573.xml.err b/result/errors/759573.xml.err index c3c5a660..74322b66 100644 --- a/result/errors/759573.xml.err +++ b/result/errors/759573.xml.err @@ -20,13 +20,3 @@ T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; Entity: line 1: %<![INCLUDE[000%ஸ000%z; ^ -./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ -./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ -./test/errors/759573.xml:1: parser error : Start tag expected, '<' not found -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ diff --git a/result/errors/759573.xml.str b/result/errors/759573.xml.str index 432f66b2..37df762d 100644 --- a/result/errors/759573.xml.str +++ b/result/errors/759573.xml.str @@ -20,11 +20,4 @@ T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; Entity: line 1: %<![INCLUDE[000%ஸ000%z; ^ -./test/errors/759573.xml:1: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ -./test/errors/759573.xml:1: parser error : DOCTYPE improperly terminated -T t (A)><!ENTITY % xx '%<![INCLUDE[000%ஸ000%z;'><!ENTITYz>%xx; - ^ ./test/errors/759573.xml : failed to parse diff --git a/result/errors/content1.xml.ent b/result/errors/content1.xml.ent index 9fcd6033..64511571 100644 --- a/result/errors/content1.xml.ent +++ b/result/errors/content1.xml.ent @@ -8,9 +8,3 @@ <!ELEMENT aElement (a |b * > ^ -./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated -<!ELEMENT aElement (a |b * > - ^ -./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found -<!ELEMENT aElement (a |b * > - ^ diff --git a/result/errors/content1.xml.err b/result/errors/content1.xml.err index 9fcd6033..64511571 100644 --- a/result/errors/content1.xml.err +++ b/result/errors/content1.xml.err @@ -8,9 +8,3 @@ <!ELEMENT aElement (a |b * > ^ -./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated -<!ELEMENT aElement (a |b * > - ^ -./test/errors/content1.xml:7: parser error : Start tag expected, '<' not found -<!ELEMENT aElement (a |b * > - ^ diff --git a/result/errors/content1.xml.str b/result/errors/content1.xml.str index d806a63d..47a6b6f8 100644 --- a/result/errors/content1.xml.str +++ b/result/errors/content1.xml.str @@ -8,7 +8,4 @@ <!ELEMENT aElement (a |b * > ^ -./test/errors/content1.xml:7: parser error : DOCTYPE improperly terminated -<!ELEMENT aElement (a |b * > - ^ ./test/errors/content1.xml : failed to parse diff --git a/result/errors10/781205.xml.err b/result/errors10/781205.xml.err index 3ddc2038..f4e0892d 100644 --- a/result/errors10/781205.xml.err +++ b/result/errors10/781205.xml.err @@ -5,13 +5,3 @@ Entity: line 1: <:0000 ^ -./test/errors10/781205.xml:4: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - - -^ -./test/errors10/781205.xml:4: parser error : DOCTYPE improperly terminated - -^ -./test/errors10/781205.xml:4: parser error : Start tag expected, '<' not found - -^ diff --git a/result/errors10/781361.xml.err b/result/errors10/781361.xml.err index 655f41a2..6153cc9a 100644 --- a/result/errors10/781361.xml.err +++ b/result/errors10/781361.xml.err @@ -5,9 +5,3 @@ ^ -./test/errors10/781361.xml:4: parser error : DOCTYPE improperly terminated - -^ -./test/errors10/781361.xml:4: parser error : Start tag expected, '<' not found - -^ diff --git a/result/valid/t8.xml.err b/result/valid/t8.xml.err index 52726946..8f874179 100644 --- a/result/valid/t8.xml.err +++ b/result/valid/t8.xml.err @@ -5,17 +5,3 @@ Entity: line 1: <!ELEMENT root (middle) > ^ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ diff --git a/result/valid/t8.xml.err.rdr b/result/valid/t8.xml.err.rdr index 8da08fbe..06b7baf7 100644 --- a/result/valid/t8.xml.err.rdr +++ b/result/valid/t8.xml.err.rdr @@ -5,18 +5,4 @@ Entity: line 1: <!ELEMENT root (middle) > ^ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -./test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot; %defmiddle; %deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ ./test/valid/t8.xml : failed to parse diff --git a/result/valid/t8a.xml.err b/result/valid/t8a.xml.err index 2846b196..211e9e86 100644 --- a/result/valid/t8a.xml.err +++ b/result/valid/t8a.xml.err @@ -5,17 +5,3 @@ Entity: line 1: <!ELEMENT root (middle) > ^ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ diff --git a/result/valid/t8a.xml.err.rdr b/result/valid/t8a.xml.err.rdr index 6abe75a9..2ae90c90 100644 --- a/result/valid/t8a.xml.err.rdr +++ b/result/valid/t8a.xml.err.rdr @@ -5,18 +5,4 @@ Entity: line 1: <!ELEMENT root (middle) > ^ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT middle (test) > -^ -./test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration - -%defroot;%defmiddle;%deftest; - ^ -Entity: line 1: -<!ELEMENT test (#PCDATA) > -^ ./test/valid/t8a.xml : failed to parse |