Bug 99641 - dbus-hash: Fix a potential shift by a negative integer
Summary: dbus-hash: Fix a potential shift by a negative integer
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: D-Bus Maintainers
QA Contact: D-Bus Maintainers
URL:
Whiteboard: weakly review+, second review would b...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-02-02 10:18 UTC by Philip Withnall
Modified: 2017-02-13 16:41 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
dbus-hash: Fix a potential shift by a negative integer (1.74 KB, patch)
2017-02-02 10:18 UTC, Philip Withnall
Details | Splinter Review

Description Philip Withnall 2017-02-02 10:18:25 UTC
Trivial patch attached.
Comment 1 Philip Withnall 2017-02-02 10:18:27 UTC
Created attachment 129288 [details] [review]
dbus-hash: Fix a potential shift by a negative integer

As a hash table becomes unbelievably large and full, the down_shift
tends towards 0. The overflow detection code in rebuild_table() does not
prevent down_shift becoming negative, which then causes undefined
behaviour in RANDOM_INDEX for int-keyed tables.

Note that this can only happen with approachint INT_MAX entries in the
hash table, at which point we’ve almost certainly hit OOM somewhere, so
this is vanishingly unlikely to happen. This is why I can’t add a test
for the bug.

As always, thanks to Coverity.

Coverity ID: 54682
Comment 2 Simon McVittie 2017-02-02 11:48:27 UTC
Comment on attachment 129288 [details] [review]
dbus-hash: Fix a potential shift by a negative integer

Review of attachment 129288 [details] [review]:
-----------------------------------------------------------------

Looks OK? Although I still hate the fact that we even have to implement a hash table here. So much of libdbus is "GLib, but not as good and under an incompatible license"...
Comment 3 Simon McVittie 2017-02-02 11:49:12 UTC
> * Hash table implementation based on generic/tclHash.c from the Tcl
> * source code.

I don't suppose you've looked at Tcl's hash table to see whether it has the same bug or has already received the same fix?
Comment 4 Philip Withnall 2017-02-02 12:26:55 UTC
(In reply to Simon McVittie from comment #3)
> > * Hash table implementation based on generic/tclHash.c from the Tcl
> > * source code.
> 
> I don't suppose you've looked at Tcl's hash table to see whether it has the
> same bug or has already received the same fix?

I didn’t notice that.

Looks like tclHash has a substantially different rebuildTable() function: https://github.com/tcltk/tcl/blob/master/generic/tclHash.c#L997

They don’t have any overflow checks for anything in there; and the downShift is never decreased again each time it is incremented by 2.

tclHash has also not seen too many changes recently: https://github.com/tcltk/tcl/commits/master/generic/tclHash.c
Comment 5 Simon McVittie 2017-02-13 16:41:39 UTC
Fixed in git for 1.11.10, thanks


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.