]> git.ipfire.org Git - thirdparty/postgresql.git/commit
ecpg: Fix handling of strings in ORACLE compat code with SQLDA
authorMichael Paquier <michael@paquier.xyz>
Tue, 18 Apr 2023 02:20:53 +0000 (11:20 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 18 Apr 2023 02:20:53 +0000 (11:20 +0900)
commita28bd77136db486b081ef392c423c89a392b3aa0
tree9b08337e01930fa9f2bd388fcd9f50693da0282b
parent9b0c1f2137fba0292b772b98b5fbccb86aedb336
ecpg: Fix handling of strings in ORACLE compat code with SQLDA

When compiled with -C ORACLE, ecpg_get_data() had a one-off issue where
it would incorrectly store the null terminator byte to str[-1] when
varcharsize is 0, which is something that can happen when using SQLDA.
This would eat 1 byte from the previous field stored, corrupting the
results generated.

All the callers of ecpg_get_data() estimate and allocate enough storage
for the data received, and the fix of this commit relies on this
assumption.  Note that this maps to the case where no padding or
truncation is required.

This issue has been introduced by 3b7ab43 with the Oracle compatibility
option, so backpatch down to v11.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20230410.173500.440060475837236886.horikyota.ntt@gmail.com
Backpatch-through: 11
src/interfaces/ecpg/ecpglib/data.c
src/interfaces/ecpg/test/compat_oracle/char_array.pgc
src/interfaces/ecpg/test/expected/compat_oracle-char_array.c
src/interfaces/ecpg/test/expected/compat_oracle-char_array.stderr
src/interfaces/ecpg/test/expected/compat_oracle-char_array.stdout