]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Avoid ecpglib core dump with out-of-order operations.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Jun 2022 22:16:46 +0000 (18:16 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Jun 2022 22:16:46 +0000 (18:16 -0400)
commitf7797747fc8fa6e5d5513e6871ee56f7cf91c51c
tree0eaa7793b732cdc08d1a8e11773742a9e4986076
parenta8c63282ddce7ab8826dfb47879c62f010b307d8
Avoid ecpglib core dump with out-of-order operations.

If an application executed operations like EXEC SQL PREPARE
without having first established a database connection, it could
get a core dump instead of the expected clean failure.  This
occurred because we did "pthread_getspecific(actual_connection_key)"
without ever having initialized the TSD key actual_connection_key.
The results of that are probably platform-specific, but at least
on Linux it often leads to a crash.

To fix, add calls to ecpg_pthreads_init() in the code paths that
might use actual_connection_key uninitialized.  It's harmless
(and hopefully inexpensive) to do that more than once.

Per bug #17514 from Okano Naoki.  The problem's ancient, so
back-patch to all supported branches.

Discussion: https://postgr.es/m/17514-edd4fad547c5692c@postgresql.org
src/interfaces/ecpg/ecpglib/connect.c