summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2017-10-16 10:48:33 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2017-10-18 08:59:09 +0200
commita217a9fea1a1cfb2bee3263b0ea08b860535af8d (patch)
treea39c9ae304e1030965d6c4ba94a412930468e7b7
parent61ef7faec8a9cf434bea4ac628824428172acaac (diff)
downloadlibrest-a217a9fea1a1cfb2bee3263b0ea08b860535af8d.tar.gz
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
-rw-r--r--rest/rest-xml-parser.c3
-rw-r--r--tests/xml.c6
2 files changed, 9 insertions, 0 deletions
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, "<invalid", -1);
+ g_assert (root == NULL);
+
root = rest_xml_parser_parse_from_data (parser, TEST_XML, strlen (TEST_XML));
g_assert (root);