pgsql: Add missing connection validation in ECPG

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add missing connection validation in ECPG
Date: 2026-05-01 19:18:14
Message-ID: E1wItNN-003dJr-2E@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
Reviewed-by: Nishant Sharma <nishant(dot)sharma(at)enterprisedb(dot)com>
Discussion: https://postgr.es/m/3007317.1765210195@sss.pgh.pa.us
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7e4c871f41814ebc694cebd544afee5c5a172e0e

Modified Files
--------------
src/interfaces/ecpg/ecpglib/descriptor.c | 12 +-
src/interfaces/ecpg/ecpglib/prepare.c | 32 +++--
src/interfaces/ecpg/test/connect/.gitignore | 2 +
src/interfaces/ecpg/test/connect/Makefile | 3 +-
src/interfaces/ecpg/test/connect/meson.build | 1 +
src/interfaces/ecpg/test/connect/test6.pgc | 68 ++++++++++
src/interfaces/ecpg/test/ecpg_schedule | 1 +
src/interfaces/ecpg/test/expected/connect-test6.c | 146 +++++++++++++++++++++
.../ecpg/test/expected/connect-test6.stderr | 50 +++++++
.../ecpg/test/expected/connect-test6.stdout | 9 ++
10 files changed, 312 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-05-03 13:22:22 pgsql: Use barrier semantics when reading/writing writtenUpto
Previous Message Andrew Dunstan 2026-05-01 17:23:52 pgsql: Only show signal-sender PID/UID detail in server log