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 661951 - _g_ir_parser_parse_file should always return a gerror if it returns NULL, causes segfaults otherwise
_g_ir_parser_parse_file should always return a gerror if it returns NULL, cau...
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2011-10-16 23:26 UTC by Alberto Ruiz
Modified: 2015-02-07 17:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes sefaults caused by _g_ir_parser_parse_file (904 bytes, patch)
2011-10-16 23:37 UTC, Alberto Ruiz
reviewed Details | Review
error is set in _g_ir_parser_parse_string when it returns NULL (464 bytes, patch)
2011-10-18 15:35 UTC, Alberto Ruiz
none Details | Review
error is set in _g_ir_parser_parse_string when it returns NULL (478 bytes, patch)
2011-10-18 15:38 UTC, Alberto Ruiz
accepted-commit_now Details | Review
Prevents a segfault when _g_ir_parser_parse_string returns NULL, error was not set (848 bytes, patch)
2011-10-18 15:50 UTC, Alberto Ruiz
none Details | Review
new patch (978 bytes, patch)
2012-02-17 09:34 UTC, Jean Bréfort
none Details | Review
updated patch (674 bytes, patch)
2012-02-17 09:59 UTC, Jean Bréfort
committed Details | Review

Description Alberto Ruiz 2011-10-16 23:26:14 UTC
When the namespace tag is not presetn, g-ir-parser segfaults instead of exiting gracefully with an error message.
Comment 1 Alberto Ruiz 2011-10-16 23:35:58 UTC
Just noticed that there was another case where _g_ir_parser_parse_file would return NULL but not a gerror. Updated bug summary.
Comment 2 Alberto Ruiz 2011-10-16 23:37:15 UTC
Created attachment 199163 [details] [review]
Fixes sefaults caused by _g_ir_parser_parse_file

This sets an error in case _g_ir_parser_parse_file fails and has to return NULL
Comment 3 Colin Walters 2011-10-18 15:24:58 UTC
Review of attachment 199163 [details] [review]:

::: girepository/girparser.c
@@ +3561,3 @@
+      return NULL;
+    }
+

That's wrong, g_file_get_contents() should *always* set an error if it returns FALSE.

@@ +3571,3 @@
+                   G_MARKUP_ERROR_INVALID_CONTENT,
+                   "Expected a namespace tag in the gir file");
+    }

And in this case, fix _g_ir_parser_parse_string() to do so too - don't patch all callers (even if there is just one).

See the rules under:
http://developer.gnome.org/glib/stable/glib-Error-Reporting.html
Comment 4 Alberto Ruiz 2011-10-18 15:35:55 UTC
Created attachment 199337 [details] [review]
error is set in _g_ir_parser_parse_string when it returns NULL
Comment 5 Alberto Ruiz 2011-10-18 15:38:11 UTC
Created attachment 199340 [details] [review]
error is set in _g_ir_parser_parse_string when it returns NULL
Comment 6 Colin Walters 2011-10-18 15:40:32 UTC
Review of attachment 199340 [details] [review]:

Patch looks right.  I generally prefer to see git-formatted patches though:
https://live.gnome.org/GnomeLove/SubmittingPatches

In this case it's helpful for someone in the future to say *why* you made this change.  For example,
"Noticed this when passing malformed .gir file to g-ir-scanner" or something.
Comment 7 Alberto Ruiz 2011-10-18 15:50:33 UTC
Created attachment 199344 [details] [review]
Prevents a segfault when _g_ir_parser_parse_string returns  NULL, error was not set
Comment 8 Alberto Ruiz 2011-10-18 15:52:52 UTC
Will do, I noticed it while using Vala to generate the .so/.gir, check #661952
Comment 9 Jean Bréfort 2012-02-17 09:34:49 UTC
Created attachment 207839 [details] [review]
new patch

Seems the patch has been commited, but it introduces a new issue: it should check if the error has not already been set, see attached patch.

Currently, I get:

GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Expected namespace element in the gir file
Comment 10 Jean Bréfort 2012-02-17 09:59:56 UTC
Created attachment 207840 [details] [review]
updated patch

Hmm, I'd left a printf-debug statement in previous patch.
Comment 11 Colin Walters 2012-02-17 16:50:15 UTC
Review of attachment 207840 [details] [review]:

Looks ok.  I changed the conditional to be if (error && *error == NULL) since the rules for GError allow for error to be NULL.
Comment 12 André Klapper 2015-02-07 17:03:01 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]