]> granicus.if.org Git - postgresql/commit
Add defenses against integer overflow in dynahash numbuckets calculations.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Dec 2012 03:09:34 +0000 (22:09 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Dec 2012 03:09:34 +0000 (22:09 -0500)
commit4b442161516797c1fca569f1421daf8f78133c55
tree58445589613f1cbf712eee6a6ba553e9bcf25d64
parent7e0d8d8457d922a63292c39862738969cac6c418
Add defenses against integer overflow in dynahash numbuckets calculations.

The dynahash code requires the number of buckets in a hash table to fit
in an int; but since we calculate the desired hash table size dynamically,
there are various scenarios where we might calculate too large a value.
The resulting overflow can lead to infinite loops, division-by-zero
crashes, etc.  I (tgl) had previously installed some defenses against that
in commit 299d1716525c659f0e02840e31fbe4dea3, but that covered only one
call path.  Moreover it worked by limiting the request size to work_mem,
but in a 64-bit machine it's possible to set work_mem high enough that the
problem appears anyway.  So let's fix the problem at the root by installing
limits in the dynahash.c functions themselves.

Trouble report and patch by Jeff Davis.
src/backend/executor/nodeHash.c
src/backend/utils/hash/dynahash.c