GNOME Bugzilla – Bug 727890
soup_content_sniffer_real_sniff segfault
Last modified: 2014-04-10 14:11:06 UTC
Hi. I am seeing a reproducible segfault in soup_content_sniffer_real_sniff when using webkit (in this example, MiniBrowser): (gdb) bt
+ Trace 233452
I'm going to try to blame this on GLib...
Created attachment 273895 [details] [review] g_str_has_prefix: don't call strlen(str) There's no reason to check the length of @str in g_str_has_prefix(), since if it's shorter than @prefix, the strncmp() will fail anyway. And besides making the function less efficient, it also breaks code like: if (buf->len >=3 && g_str_has_prefix (buf->data, "foo")) ... which really looks like it ought to work whether buf->data is nul-terminated or not.
(In reply to comment #2) > Created an attachment (id=273895) [details] [review] > g_str_has_prefix: don't call strlen(str) Hi Dan. This seems to do the trick :-) I haven't been unable to trigger the segfault so far..
Found same issue, see https://github.com/conformal/xombrero/issues/58 And you're right, there's no need to check the length of str at all, my proposed fix to g_str_has_prefix used strnlen limited by the length of the prefix. But even that is not necessary.
Review of attachment 273895 [details] [review]: You can commit this now, if you like, or you can try to do it open-coded to avoid taking the strlen() of the prefix when very likely we will reject on the very first character comparison... ::: glib/gstrfuncs.c @@ +2798,3 @@ g_return_val_if_fail (prefix != NULL, FALSE); + return strncmp (str, prefix, strlen (prefix)) == 0; This is obviously better than the existing code.
pushed to master and glib-2-40