postgresql/src/backend/utils
Tom Lane 0c1caa48d3 Prevent integer overflows in array subscripting calculations.
While we were (mostly) careful about ensuring that the dimensions of
arrays aren't large enough to cause integer overflow, the lower bound
values were generally not checked.  This allows situations where
lower_bound + dimension overflows an integer.  It seems that that's
harmless so far as array reading is concerned, except that array
elements with subscripts notionally exceeding INT_MAX are inaccessible.
However, it confuses various array-assignment logic, resulting in a
potential for memory stomps.

Fix by adding checks that array lower bounds aren't large enough to
cause lower_bound + dimension to overflow.  (Note: this results in
disallowing cases where the last subscript position would be exactly
INT_MAX.  In principle we could probably allow that, but there's a lot
of code that computes lower_bound + dimension and would need adjustment.
It seems doubtful that it's worth the trouble/risk to allow it.)

Somewhat independently of that, array_set_element() was careless
about possible overflow when checking the subscript of a fixed-length
array, creating a different route to memory stomps.  Fix that too.

Security: CVE-2021-32027
2021-05-10 10:44:38 -04:00
..
adt Prevent integer overflows in array subscripting calculations. 2021-05-10 10:44:38 -04:00
cache Fix inconsistent code with shared invalidations of snapshots 2020-12-28 22:17:16 +09:00
error Disallow setting client_min_messages higher than ERROR. 2018-11-08 17:33:26 -05:00
fmgr Fix broken ruleutils support for function TRANSFORM clauses. 2021-01-25 13:03:12 -05:00
hash Remove broken and useless entry-count printing in HASH_DEBUG code. 2017-08-02 12:16:57 -04:00
init Fix postmaster's behavior during smart shutdown. 2020-08-14 13:26:57 -04:00
mb Avoid unnecessary out-of-memory errors during encoding conversion. 2019-10-03 17:34:26 -04:00
misc Fix some inappropriately-disallowed uses of ALTER ROLE/DATABASE SET. 2021-04-13 15:10:18 -04:00
mmgr Allow repalloc() to give back space when a large chunk is downsized. 2019-10-03 13:56:26 -04:00
resowner pgindent run for 9.6 2016-06-09 18:02:36 -04:00
sort Backpatch tuplesort.c assertion. 2020-07-29 16:00:50 -07:00
time Fix pruning of locked and updated tuples. 2017-12-14 18:20:48 -08:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Add the "snapshot too old" feature 2016-04-08 14:36:30 -05:00
Gen_dummy_probes.pl Finish pgindent run for 9.6: Perl files. 2016-06-12 04:19:56 -04:00
Gen_dummy_probes.sed Update copyright for 2016 2016-01-02 13:33:40 -05:00
Gen_fmgrtab.pl Update copyright for 2016 2016-01-02 13:33:40 -05:00
generate-errcodes.pl Update copyright for 2016 2016-01-02 13:33:40 -05:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
probes.d Update copyright for 2016 2016-01-02 13:33:40 -05:00