]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add missing connection validation in ECPG
authorAndrew Dunstan <andrew@dunslane.net>
Fri, 1 May 2026 19:12:28 +0000 (15:12 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Fri, 1 May 2026 19:16:02 +0000 (15:16 -0400)
commit6916f44100515b7d939f034a2c78caef4047209e
tree98c52508867fbae5c26cde3958c0407d1c7db7d4
parente4f035de455e54653a811fda35d1458ec73def60
Add missing connection validation in ECPG

ECPGdeallocate_all(), ECPGprepared_statement(), ECPGget_desc(), and
ecpg_freeStmtCacheEntry() could crash with a SIGSEGV when called
without an established connection (for example, when EXEC SQL CONNECT
was forgotten or a non-existent connection name was used), because
they dereferenced the result of ecpg_get_connection() without first
checking it for NULL.

Each site is fixed in the style of the surrounding code.

New tests are added for these conditions.

Author: Shruthi Gowda <gowdashru@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Mahendra Singh Thalor <mahi6run@gmail.com>
Reviewed-by: Nishant Sharma <nishant.sharma@enterprisedb.com>
Discussion: https://postgr.es/m/3007317.1765210195@sss.pgh.pa.us
Backpatch-through: 14
src/interfaces/ecpg/ecpglib/descriptor.c
src/interfaces/ecpg/ecpglib/prepare.c
src/interfaces/ecpg/test/connect/.gitignore
src/interfaces/ecpg/test/connect/Makefile
src/interfaces/ecpg/test/connect/test6.pgc [new file with mode: 0644]
src/interfaces/ecpg/test/ecpg_schedule
src/interfaces/ecpg/test/expected/connect-test6.c [new file with mode: 0644]
src/interfaces/ecpg/test/expected/connect-test6.stderr [new file with mode: 0644]
src/interfaces/ecpg/test/expected/connect-test6.stdout [new file with mode: 0644]