After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 789053 - xml: Don't crash parsing empty XML string
xml: Don't crash parsing empty XML string
Status: RESOLVED FIXED
Product: librest
Classification: Platform
Component: xml-parser
git master
Other All
: Normal normal
: ---
Assigned To: librest-maint
librest-maint
Depends on:
Blocks:
 
 
Reported: 2017-10-16 12:33 UTC by Christophe Fergeau
Modified: 2017-10-18 06:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
xml: Don't crash parsing empty XML string (1.62 KB, patch)
2017-10-16 12:33 UTC, Christophe Fergeau
committed Details | Review

Description Christophe Fergeau 2017-10-16 12:33:16 UTC
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.
Comment 1 Christophe Fergeau 2017-10-16 12:33:21 UTC
Created attachment 361668 [details] [review]
xml: Don't crash parsing empty XML string
Comment 2 Debarshi Ray 2017-10-17 14:35:12 UTC
Review of attachment 361668 [details] [review]:

I am not a librest developer, but it looks good to me.

::: tests/xml.c
@@ +36,3 @@
 
+  root = rest_xml_parser_parse_from_data (parser, "", -1);
+  g_assert (root == NULL);

I wonder if we should switch to g_assert_null and friends in future.

@@ +38,3 @@
+  g_assert (root == NULL);
+  root = rest_xml_parser_parse_from_data (parser, "<invalid", -1);
+  g_assert (root == NULL);

Nitpick: maybe a newline after this for aesthetics?
Comment 3 Christophe Fergeau 2017-10-18 06:59:44 UTC
Attachment 361668 [details] pushed as a217a9f - xml: Don't crash parsing empty XML string