]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Guard against overflow in interval_mul() and interval_div().
authorDean Rasheed <dean.a.rasheed@gmail.com>
Sat, 18 Nov 2023 14:46:02 +0000 (14:46 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Sat, 18 Nov 2023 14:46:02 +0000 (14:46 +0000)
commit72d0c135bd7a9ab4602ea1bece0054bb1e8d372d
tree588f632158ab26ea010b7317fa9b52120b11872b
parent3b6728910ace14c64ffa43b538a84508f4fe6408
Guard against overflow in interval_mul() and interval_div().

Commits 146604ec43 and a898b409f6 added overflow checks to
interval_mul(), but not to interval_div(), which contains almost
identical code, and so is susceptible to the same kinds of
overflows. In addition, those checks did not catch all possible
overflow conditions.

Add additional checks to the "cascade down" code in interval_mul(),
and copy all the overflow checks over to the corresponding code in
interval_div(), so that they both generate "interval out of range"
errors, rather than returning bogus results.

Given that these errors are relatively easy to hit, back-patch to all
supported branches.

Per bug #18200 from Alexander Lakhin, and subsequent investigation.

Discussion: https://postgr.es/m/18200-5ea288c7b2d504b1%40postgresql.org
src/backend/utils/adt/timestamp.c
src/test/regress/expected/interval.out
src/test/regress/sql/interval.sql