aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-05-13 10:53:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2019-05-13 10:53:19 -0400
commit0ec3d2ab250ef696f5e32d4ff7779849bfb0770d (patch)
tree72eae48502e75b80ca2623a50db96420370771c1
parentd6de52636827ab64f537eb78657db125b082bb65 (diff)
downloadpostgresql-0ec3d2ab250ef696f5e32d4ff7779849bfb0770d.tar.gz
postgresql-0ec3d2ab250ef696f5e32d4ff7779849bfb0770d.zip
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 4e86f1b16, 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
-rw-r--r--src/interfaces/libpq/fe-misc.c2
-rw-r--r--src/interfaces/libpq/fe-secure-openssl.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index b7b53d3a71c..291b6274098 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -1064,7 +1064,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
#ifdef USE_SSL
/* 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 */
return 1;
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 0d0a3660f50..84eb024d6b9 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -152,7 +152,7 @@ pgtls_open_client(PGconn *conn)
bool
pgtls_read_pending(PGconn *conn)
{
- return SSL_pending(conn->ssl);
+ return SSL_pending(conn->ssl) > 0;
}
/*