BUG #17514: Application with embedded SQL crashes when executing EXEC SQL PREPARE

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: okano(dot)naoki(at)jp(dot)fujitsu(dot)com
Subject: BUG #17514: Application with embedded SQL crashes when executing EXEC SQL PREPARE
Date: 2022-06-09 06:40:28
Message-ID: 17514-edd4fad547c5692c@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17514
Logged by: Okano Naoki
Email address: okano(dot)naoki(at)jp(dot)fujitsu(dot)com
PostgreSQL version: 12.9
Operating system: RHEL 7
Description:

Hi,

Application with embedded SQL crashes with segmentation fault if I execute
EXEC SQL PREPARE
command before executing EXEC SQL CONNECT command (*1).
I know that it is the correct operation to execute EXEC SQL CONNECT command
first
and then execute EXEC SQL PREPARE command.
But I expect this wrong operation to result in an error, not a crash.
Is it correct that this operation causes the application to crash? Or is it
a bug?

[Environment]
* OS version: RHEL 7
* PostgreSQL version: 12
I checked that PostgreSQL 10 and 14 also occurred a same issue.

(*1) Here is an exapmle.
int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
char *connection = "tcp:postgresql://localhost/postgres";
char *user = "user_name";
EXEC SQL END DECLARE SECTION;

ECPGdebug(1, stderr);

/* Skip a CONNECT command deliberately. */
/* EXEC SQL CONNECT TO :connection USER :user; */

EXEC SQL PREPARE stmt1 FROM "SELECT * FROM pg_database WHERE oid = ?";
return (0);
}

The following is a backtrace of the coredump.
(gdb) bt
#0 0x00007f9b4d4da150 in parseInput () from
/opt/rh/rh-postgresql12/root/usr//lib64/libpq.so.rh-postgresql12-5
#1 0x00007f9b4d4dc60d in PQgetResult () from
/opt/rh/rh-postgresql12/root/usr//lib64/libpq.so.rh-postgresql12-5
#2 0x00007f9b4d4dc8cf in PQexecStart () from
/opt/rh/rh-postgresql12/root/usr//lib64/libpq.so.rh-postgresql12-5
#3 0x00007f9b4d4dcb6c in PQprepare () from
/opt/rh/rh-postgresql12/root/usr//lib64/libpq.so.rh-postgresql12-5
#4 0x00007f9b4dd01a61 in prepare_common () from
/opt/rh/rh-postgresql12/root/usr//lib64/libecpg.so.rh-postgresql12-6
#5 0x00007f9b4dd01fb5 in ECPGprepare () from
/opt/rh/rh-postgresql12/root/usr//lib64/libecpg.so.rh-postgresql12-6
#6 0x0000000000400a79 in main ()

Thanks in advance.

Regards,
Naoki Okano

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2022-06-09 07:38:38 Re: psql 15beta1 does not print notices on the console until transaction completes
Previous Message Noah Misch 2022-06-09 05:17:08 Re: Extension pg_trgm, permissions and pg_dump order