From ef44aeb069a7f26d47f7b51bc033d3964ab3e0d9 Mon Sep 17 00:00:00 2001 From: sherlock2010 <15151851377@163.com> Date: Wed, 9 Nov 2022 03:07:31 +0000 Subject: [PATCH] xml do not crash parsing empty XML string --- ...Don-t-crash-parsing-empty-XML-string.patch | 50 +++++++++++++++++++ rest.spec | 9 +++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 backport-xml-Don-t-crash-parsing-empty-XML-string.patch diff --git a/backport-xml-Don-t-crash-parsing-empty-XML-string.patch b/backport-xml-Don-t-crash-parsing-empty-XML-string.patch new file mode 100644 index 0000000..e6b9a2f --- /dev/null +++ b/backport-xml-Don-t-crash-parsing-empty-XML-string.patch @@ -0,0 +1,50 @@ +From a217a9fea1a1cfb2bee3263b0ea08b860535af8d Mon Sep 17 00:00:00 2001 +From: Christophe Fergeau +Date: Mon, 16 Oct 2017 10:48:33 +0200 +Subject: [PATCH] xml: Don't crash parsing empty XML string + +Calling rest_xml_parser_parse_from_data() with an empty string ("") +currently causes a crash as xmlReaderForMemory() returns NULL in that +case, and we then try to dereference this pointer without checking it's +non-NULL. + +https://bugzilla.gnome.org/show_bug.cgi?id=789053 +--- + rest/rest-xml-parser.c | 3 +++ + tests/xml.c | 6 ++++++ + 2 files changed, 9 insertions(+) + +diff --git a/rest/rest-xml-parser.c b/rest/rest-xml-parser.c +index ffa6ff3..796052e 100644 +--- a/rest/rest-xml-parser.c ++++ b/rest/rest-xml-parser.c +@@ -103,6 +103,9 @@ rest_xml_parser_parse_from_data (RestXmlParser *parser, + NULL, /* URL? */ + NULL, /* encoding */ + XML_PARSE_RECOVER | XML_PARSE_NOCDATA); ++ if (reader == NULL) { ++ return NULL; ++ } + xmlTextReaderSetErrorHandler(reader, rest_xml_parser_xml_reader_error, NULL); + + while (xmlTextReaderRead (reader) == 1) +diff --git a/tests/xml.c b/tests/xml.c +index 4b7718b..9d03e29 100644 +--- a/tests/xml.c ++++ b/tests/xml.c +@@ -34,6 +34,12 @@ main (int argc, char **argv) + + parser = rest_xml_parser_new (); + ++ root = rest_xml_parser_parse_from_data (parser, "", -1); ++ g_assert (root == NULL); ++ ++ root = rest_xml_parser_parse_from_data (parser, " - 0.8.1-8 +- Type:bugfix +- Id:NA +- SUG:NA +- DESC:xml do not crash parsing empty XML string + * Sat Nov 23 2019 openEuler Buildteam - 0.8.1-7 - Type:bugfix - Id:NA