pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: okano.naoki@jp.fujitsu.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17514: Application with embedded SQL crashes when executing EXEC SQL PREPARE
Date: Thu, 09 Jun 2022 13:01:36 -0400
Message-ID: <2060083.1654794096@sss.pgh.pa.us> (raw)
In-Reply-To: <17514-edd4fad547c5692c@postgresql.org>
References: <17514-edd4fad547c5692c@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> 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.

We could do something like the attached, perhaps.  Having said that,
an application that includes no error checks is pretty unlikely to
fail gracefully :-(.

			regards, tom lane

Attachments:

ensure-TSD-key-is-valid-before-use.patch (text/x-diff, 837B) download diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 8dfcabe3b5..90f2ba9701 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -40,6 +40,8 @@ ecpg_get_connection_nr(const char *connection_name) if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0)) { #ifdef ENABLE_THREAD_SAFETY + ecpg_pthreads_init(); /* ensure actual_connection_key is valid */ + ret = pthread_getspecific(actual_connection_key); /* @@ -78,6 +78,8 @@ ecpg_get_connection(const char *connection_name) if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0)) { #ifdef ENABLE_THREAD_SAFETY + ecpg_pthreads_init(); /* ensure actual_connection_key is valid */ + ret = pthread_getspecific(actual_connection_key); /*

view thread (4+ messages)  latest in thread

Message-ID: <2060083.1654794096@sss.pgh.pa.us>
Permalink:  ../2060083.1654794096@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2060083.1654794096@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, okano.naoki@jp.fujitsu.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17514: Application with embedded SQL crashes when executing EXEC SQL PREPARE
  In-Reply-To: <2060083.1654794096@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox