]> granicus.if.org Git - postgresql/commitdiff
Set errno to zero before invoking SSL_read or SSL_write. It appears that
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Dec 2009 03:46:01 +0000 (03:46 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Dec 2009 03:46:01 +0000 (03:46 +0000)
at least in some Windows versions, these functions are capable of returning
a failure indication without setting errno.  That puts us into an infinite
loop if the previous value happened to be EINTR.  Per report from Brendan
Hill.

Back-patch to 8.2.  We could take it further back, but since this is only
known to be an issue on Windows and we don't support Windows before 8.2,
it does not seem worth the trouble.

src/backend/libpq/be-secure.c
src/interfaces/libpq/fe-secure.c

index e3a7abc205ec254fdfb3ee7020bae562876a6c51..b3a4416f244db13027877b0b16a86c35cc56f609 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.83.2.2 2009/12/09 06:37:25 mha Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.83.2.3 2009/12/30 03:46:01 tgl Exp $
  *
  *       Since the server static private key ($DataDir/server.key)
  *       will normally be stored unencrypted so that the database
@@ -269,6 +269,7 @@ secure_read(Port *port, void *ptr, size_t len)
                int                     err;
 
 rloop:
+               errno = 0;
                n = SSL_read(port->ssl, ptr, len);
                err = SSL_get_error(port->ssl, n);
                switch (err)
@@ -363,6 +364,7 @@ secure_write(Port *port, void *ptr, size_t len)
                }
 
 wloop:
+               errno = 0;
                n = SSL_write(port->ssl, ptr, len);
                err = SSL_get_error(port->ssl, n);
                switch (err)
index a1aa046340720a791c7aef603fcd7dcecb9c8c09..9c4f636d3e73d1cc688a41509f6ede48e52afd38 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.102.2.2 2009/12/09 06:37:25 mha Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.102.2.3 2009/12/30 03:46:01 tgl Exp $
  *
  * NOTES
  *       [ Most of these notes are wrong/obsolete, but perhaps not all ]
@@ -316,6 +316,7 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
                DISABLE_SIGPIPE(return -1);
 
 rloop:
+               SOCK_ERRNO_SET(0);
                n = SSL_read(conn->ssl, ptr, len);
                err = SSL_get_error(conn->ssl, n);
                switch (err)
@@ -400,6 +401,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
        {
                int                     err;
 
+               SOCK_ERRNO_SET(0);
                n = SSL_write(conn->ssl, ptr, len);
                err = SSL_get_error(conn->ssl, n);
                switch (err)