BUG #11712: Empty string as error message from libpq

From: marko(at)joh(dot)to
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #11712: Empty string as error message from libpq
Date: 2014-10-19 00:37:36
Message-ID: 20141019003736.2662.84048@wrigleys.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: 11712
Logged by: Marko Tiikkaja
Email address: marko(at)joh(dot)to
PostgreSQL version: 9.4beta2
Operating system: OS X
Description:

Hi,

This has been annoying me for a while, but I never got around to reporting
the bug. Reproduced on 9.1 and just tried against HEAD. Here it is in all
its glory.

Consider a program similar to the LISTEN/NOTIFY example here:
http://www.postgresql.org/docs/9.3/static/libpq-example.html#LIBPQ-EXAMPLE-2,
but with an added error handling around PQconsumeInput():

if (PQconsumeInput(conn) != 1) {
fprintf(stderr,
"PQconsumeInput() failed: %s\n",
PQerrorMessage(conn));
PQfinish(conn);
return;
}

Now when this program is running without SSL, and the server closes the
network connection, what happens is this:

PQconsumeInput() failed:

i.e. the error string is empty. This happens when recv() returns 0 on EOF.
pqsecure_write() says the following: "On failure, this function is
responsible for putting a suitable message into conn->errorMessage", but
apparently it doesn't consider recv() returning 0 a "failure", which I guess
is fine. However, pqReadData() goes through all the fancy logic of
determining that what happened was really an EOF, and then says the
following:

/*
* OK, we are getting a zero read even though select() says ready. This
* means the connection has been closed. Cope. Note that errorMessage
* has been set already.
*/

But I don't see who's supposed to have been set errorMessage in that case.
I think that might be true for SSL code paths, but it's certainly not true
for the non-SSL ones.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-10-19 20:14:29 Re: BUG #10680: LDAP bind password leaks to log on failed authentication
Previous Message Tom Lane 2014-10-17 22:26:15 Re: BUG #11703: ERROR: variable not found in subplan target list