]> git.ipfire.org Git - thirdparty/postgresql.git/commit
ecpg: Fix out-of-bound read in DecodeDateTime()
authorMichael Paquier <michael@paquier.xyz>
Tue, 22 Oct 2024 23:35:00 +0000 (08:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 22 Oct 2024 23:35:00 +0000 (08:35 +0900)
commit2c37cb26f8af0aecb1b534585f3a0234f70e69ee
tree522ac1f41f86b55ec141cba21e372afa346517aa
parent5914a22f6ea5a3a8485cf626e76a63f3f6463de4
ecpg: Fix out-of-bound read in DecodeDateTime()

It was possible for the code to read out-of-bound data from the
"day_tab" table with some crafted input data.  Let's treat these as
invalid input as the month number is incorrect.

A test is added to test this case with a check on the errno returned by
the decoding routine.  A test close to the new one added in this commit
was testing for a failure, but did not look at the errno generated, so
let's use this commit to also change it, adding a check on the errno
returned by DecodeDateTime().

Like the other test scripts, dt_test should likely be expanded to
include more checks based on the errnos generated in these code paths.
This is left as future work.

This issue exists since 2e6f97560a83, so backpatch all the way down.

Reported-by: Pavel Nekrasov
Author: Bruce Momjian, Pavel Nekrasov
Discussion: https://postgr.es/m/18614-6bbe00117352309e@postgresql.org
Backpatch-through: 12
src/interfaces/ecpg/pgtypeslib/dt_common.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout
src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc