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 675939 - girepository: avoid crash when querying nonexistent info
girepository: avoid crash when querying nonexistent info
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-05-12 13:11 UTC by Pavel Holejsovsky
Modified: 2015-02-07 16:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
girepository: avoid crash when querying nonexistent info (2.74 KB, patch)
2012-05-12 13:13 UTC, Pavel Holejsovsky
reviewed Details | Review
girepository: avoid crash when querying nonexistent info (5.10 KB, patch)
2012-05-12 18:49 UTC, Pavel Holejsovsky
committed Details | Review

Description Pavel Holejsovsky 2012-05-12 13:11:35 UTC
It appears that cmph library can return (n+1) when querying item not
present in its original n-item-sized set.  Adjust code so that it
detects this condition and do not chase stray pointers resulting from
this bogus hash result.
Comment 1 Pavel Holejsovsky 2012-05-12 13:13:31 UTC
Created attachment 213917 [details] [review]
girepository: avoid crash when querying nonexistent info

It appears that cmph library can return (n+1) when querying item not
present in its original n-item-sized set.  Adjust code so that it
detects this condition and do not chase stray pointers resulting from
this bogus hash result.
Comment 2 Colin Walters 2012-05-12 14:13:28 UTC
Review of attachment 213917 [details] [review]:

::: girepository/gitypelib.c
@@ +190,2 @@
       index = _gi_typelib_hash_search (hash, name);
+      if (index < n_entries)

This seems wrong to me; note that inside _gi_typelib_hash_search, we use the integer returned by BDZ as an index into another lookup table.  See the comment in girepository/gthash.c.

If the bug indeed lies inside BDZ, then the right fix is probably to detect this inside _gi_typelib_hash_search().  That function is supposed to always return a valid value though...

This needs more investigation.
Comment 3 Pavel Holejsovsky 2012-05-12 18:33:01 UTC
(In reply to comment #2)
> Review of attachment 213917 [details] [review]:
> 
> ::: girepository/gitypelib.c
> @@ +190,2 @@
>        index = _gi_typelib_hash_search (hash, name);
> +      if (index < n_entries)
> 
> This seems wrong to me; note that inside _gi_typelib_hash_search, we use the
> integer returned by BDZ as an index into another lookup table.  See the comment
> in girepository/gthash.c.

You are right, I knew that but somehow forgot it when writing a patch.  I'll try to come with something better.

> If the bug indeed lies inside BDZ, then the right fix is probably to detect
> this inside _gi_typelib_hash_search().  That function is supposed to always
> return a valid value though...

Given that for the testcase appended in the patch BDZ really generates out-of-range index, I guess we have to somehow handle it.  I suggest to detect this index overrun inside _gi_typelib_hash_search and return 0-th entry of the lookup table (as if BDZ returned 0).  Then later g_typelib_get_dir_entry_by_name() detects that names differ (using strcmp) and DTRT.  Preparing patch right now...

> This needs more investigation.

I guess that the main question is whether BDZ behaviour is correct in this case; but I'm absolutely uneducated in the area of hash/crypto calculations, so someone else would have to check the BDZ algo/impl for the correctness in this case.
Comment 4 Pavel Holejsovsky 2012-05-12 18:49:36 UTC
Created attachment 213932 [details] [review]
girepository: avoid crash when querying nonexistent info

It appears that cmph library can return (n+1) when querying item not
present in its original n-item-sized set.  Adjust code so that it
detects this condition and do not chase stray pointers resulting from
this bogus(?) hash result.
Comment 5 Colin Walters 2012-05-13 13:31:37 UTC
Review of attachment 213932 [details] [review]:

Looks good, thank you!
Comment 6 Pavel Holejsovsky 2012-05-13 13:56:53 UTC
Attachment 213932 [details] pushed as d055d35 - girepository: avoid crash when querying nonexistent info
Comment 7 André Klapper 2015-02-07 16:57:25 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]