The following bug has been logged on the website:
Bug reference: 17514
Logged by: Okano Naoki
Email address: okano.naoki@jp.fujitsu.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