BUG #19967: ecpg crashes after "cursor does not exist" on FETCH or MOVE

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: aman(at)stack-auth(dot)com
Subject: BUG #19967: ecpg crashes after "cursor does not exist" on FETCH or MOVE
Date: 2026-12-02 01:20:17
Message-ID: 19967-20b057703e28f235@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19967
Logged by: Aman Ganapathy
Email address: aman(at)stack-auth(dot)com
PostgreSQL version: 19.0
Operating system: Debian 13 (trixie), aarch64
Description:

ecpg crashes with a segmentation fault when a FETCH or MOVE names a
cursor that was never declared. It prints the expected "cursor does not
exist" error first. OPEN of the same undeclared cursor prints the same
error and exits with status 3 without crashing.

Setup: the official postgres:19.0 Docker image, with ecpg installed by

apt-get update && apt-get install -y libecpg-dev

which installs ecpg 19.0 (Debian 19.0-2.pgdg13+1).

Test case. fetch.pgc:

int main(void)
{
EXEC SQL FETCH nosuch;
return 0;
}

open.pgc is the same with "EXEC SQL OPEN nosuch;" on line 3.

Commands, run with sh in a directory containing the two files:

ecpg fetch.pgc; echo "exit status $?"
ls fetch.c
ecpg open.pgc; echo "exit status $?"
ls open.c

Output:

fetch.pgc:3: ERROR: cursor "nosuch" does not exist
Segmentation fault
exit status 139
fetch.c
open.pgc:3: ERROR: cursor "nosuch" does not exist
exit status 3
ls: cannot access 'open.c': No such file or directory

The same crash happens with "EXEC SQL MOVE nosuch;" and
"EXEC SQL FETCH NEXT FROM nosuch;".

Expected: the same as for OPEN, i.e. the error message, exit status 3,
and no output file left behind.

The same output on master at b4cc5e924b7 (2026-11-25), built with
--enable-debug --with-icu --enable-cassert.

Environment: ecpg (PostgreSQL) 19.0 (Debian 19.0-2.pgdg13+1), package
libecpg-dev 19.0-2.pgdg13+1. Debian 13 (trixie) in the image, Linux
7.0.14 aarch64, glibc 2.41, 14 CPUs, 16 GB RAM, running in an OrbStack
VM on macOS 15.7.9 (Apple Silicon).

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-12-02 01:39:50 BUG #19968: ALTER COLUMN TYPE fails with internal errors if a dependent object is dropped concurrently
Previous Message shihao zhong 2026-12-02 00:55:34 Re: Hot Standby: missing snapshot conflicts in CREATE INDEX, rewrite, hash