pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: hirose.masay-01@fujitsu.com <hirose.masay-01@fujitsu.com>
Cc: 'Michael Paquier' <michael@paquier.xyz>
Cc: 'pgsql-bugs@lists.postgresql.org' <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #17421: Core dump in ECPGdo() when calling PostgreSQL API from 32-bit client for RHEL8
Date: Mon, 06 Jun 2022 11:01:52 -0400
Message-ID: <908758.1654527712@sss.pgh.pa.us> (raw)
In-Reply-To: <TYYPR01MB68109C3C722F18E2D070F350B8A29@TYYPR01MB6810.jpnprd01.prod.outlook.com>
References: <17421-790ff887e3188874@postgresql.org>
	<YhtsqXFtjC86HdeM@paquier.xyz>
	<2360630.1645979458@sss.pgh.pa.us>
	<TYYPR01MB68107FD3A60E960453525BF7B8069@TYYPR01MB6810.jpnprd01.prod.outlook.com>
	<YiM7gxu7cxarLUc4@paquier.xyz>
	<4070596.1646493542@sss.pgh.pa.us>
	<OSZPR01MB68168671C4115AF080C69610B8E79@OSZPR01MB6816.jpnprd01.prod.outlook.com>
	<TYYPR01MB68109C3C722F18E2D070F350B8A29@TYYPR01MB6810.jpnprd01.prod.outlook.com>

"hirose.masay-01@fujitsu.com" <hirose.masay-01@fujitsu.com> writes:
> [Problem]
> The potential problem is no value is set to "message" after PQresultErrorField() is called in ecpg_raise_backend().

Ah-hah.  You're right, and this explains the symptoms exactly, because
libpq-generated error results don't contain broken-down fields, so we'd
get a null precisely in cases such as lost connection.

> |		if (message == NULL)
> |			message = ecpg_gettext("empty message text");

No, that'd be pretty unhelpful.  The best response is to substitute
PQerrorMessage(conn) in such cases.  We do that in, for example,
postgres_fdw.

(I don't feel a need to change ECPGnoticeReceiver, because that only
deals with NOTICE results which should always have such a field, and
PQerrorMessage wouldn't be relevant to a non-ERROR result anyway.)

Will fix, thanks for the report!

			regards, tom lane

Attachments:

  [text/x-diff] ecpg-cope-with-missing-primary-error-field.patch (1.1K, ../908758.1654527712@sss.pgh.pa.us/2-ecpg-cope-with-missing-primary-error-field.patch)
  download | inline diff:
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index cd6c6a6819..26fdcdb69e 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -229,18 +229,17 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
 		return;
 	}
 
-	if (result)
-	{
-		sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
-		if (sqlstate == NULL)
-			sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
-		message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
-	}
-	else
-	{
+	/*
+	 * PQresultErrorField will return NULL if "result" is NULL, or if there is
+	 * no such field, which will happen for libpq-generated errors.  Fall back
+	 * to PQerrorMessage in such cases.
+	 */
+	sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
+	if (sqlstate == NULL)
 		sqlstate = ECPG_SQLSTATE_ECPG_INTERNAL_ERROR;
+	message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
+	if (message == NULL)
 		message = PQerrorMessage(conn);
-	}
 
 	if (strcmp(sqlstate, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR) == 0)
 	{

view thread (10+ messages)  latest in thread

Message-ID: <908758.1654527712@sss.pgh.pa.us>
Permalink:  ../908758.1654527712@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/908758.1654527712@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, hirose.masay-01@fujitsu.com, michael@paquier.xyz, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17421: Core dump in ECPGdo() when calling PostgreSQL API from 32-bit client for RHEL8
  In-Reply-To: <908758.1654527712@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