]> granicus.if.org Git - postgresql/commitdiff
Fix misuse of an integer as a bool.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 May 2019 14:53:19 +0000 (10:53 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 May 2019 14:53:19 +0000 (10:53 -0400)
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

src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-secure-openssl.c

index cac6359585ee370a522aa6f223e1bd51a62d525d..864e8853aeb1df36d0ba44d0b7657971d0e8b11e 100644 (file)
@@ -1059,7 +1059,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;
index f6636d1607afd24f3e7c1d5fc9b14e02417ecc38..e8b917909f680bffe8f8206f18c7a616db44fc0e 100644 (file)
@@ -150,7 +150,7 @@ pgtls_open_client(PGconn *conn)
 bool
 pgtls_read_pending(PGconn *conn)
 {
-       return SSL_pending(conn->ssl);
+       return SSL_pending(conn->ssl) > 0;
 }
 
 /*