Commit ddf927fb authored by Tom Lane's avatar Tom Lane

Fix misuse of an integer as a bool.

pgtls_read_pending is declared to return bool, but what the underlying
SSL_pending function returns is a count of available bytes.

This is actually somewhat harmless if we're using C99 bools, but in
the back branches it's a live bug: if the available-bytes count happened
to be a multiple of 256, it would get converted to a zero char value.
On machines where char is signed, counts of 128 and up could misbehave
as well.  The net effect is that when using SSL, libpq might block
waiting for data even though some has already been received.

Broken by careless refactoring in commit 4e86f1b1, so back-patch
to 9.5 where that came in.

Per bug #15802 from David Binderman.

Discussion: https://postgr.es/m/15802-f0911a97f0346526@postgresql.org
parent cc866941
...@@ -1094,7 +1094,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time) ...@@ -1094,7 +1094,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
#ifdef USE_SSL #ifdef USE_SSL
/* Check for SSL library buffering read bytes */ /* Check for SSL library buffering read bytes */
if (forRead && conn->ssl_in_use && pgtls_read_pending(conn) > 0) if (forRead && conn->ssl_in_use && pgtls_read_pending(conn))
{ {
/* short-circuit the select */ /* short-circuit the select */
return 1; return 1;
......
...@@ -264,7 +264,7 @@ rloop: ...@@ -264,7 +264,7 @@ rloop:
bool bool
pgtls_read_pending(PGconn *conn) pgtls_read_pending(PGconn *conn)
{ {
return SSL_pending(conn->ssl); return SSL_pending(conn->ssl) > 0;
} }
ssize_t ssize_t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment