Add missing connection validation in ECPG
Andrew Dunstan <andrew@dunslane.net>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/interfaces/ecpg/ecpglib/descriptor.c | modified | +10 −2 |
| src/interfaces/ecpg/ecpglib/prepare.c | modified | +23 −9 |
| src/interfaces/ecpg/test/connect/.gitignore | modified | +2 −0 |
| src/interfaces/ecpg/test/connect/Makefile | modified | +2 −1 |
| src/interfaces/ecpg/test/connect/test6.pgc | added | +68 −0 |
| src/interfaces/ecpg/test/ecpg_schedule | modified | +1 −0 |
| src/interfaces/ecpg/test/expected/connect-test6.c | added | +146 −0 |
| src/interfaces/ecpg/test/expected/connect-test6.stderr | added | +50 −0 |
| src/interfaces/ecpg/test/expected/connect-test6.stdout | added | +9 −0 |
Discussion
- [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL 28 messages · 2025-12-08 → 2026-05-26