aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-12-30 03:45:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-12-30 03:45:46 +0000
commit4847d5956c58faad15d03926e2cf97d59822a6ae (patch)
tree6bec006b88679681259317c499b00cfaa5a1c86d /src
parent3d4b0ab29cfee7cbb9932065216b58b6c820a791 (diff)
downloadpostgresql-4847d5956c58faad15d03926e2cf97d59822a6ae.tar.gz
postgresql-4847d5956c58faad15d03926e2cf97d59822a6ae.zip
Set errno to zero before invoking SSL_read or SSL_write. It appears that
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/libpq/be-secure.c4
-rw-r--r--src/interfaces/libpq/fe-secure.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index 3e4756f1c7c..e740ae6f877 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.93 2009/12/09 06:37:06 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.94 2009/12/30 03:45:46 tgl Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
@@ -245,6 +245,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)
@@ -339,6 +340,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)
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 6f6052b2b05..f58be75f8a2 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.129 2009/12/09 06:37:06 mha Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.130 2009/12/30 03:45:46 tgl Exp $
*
* NOTES
*
@@ -324,6 +324,7 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
DISABLE_SIGPIPE(conn, spinfo, return -1);
rloop:
+ SOCK_ERRNO_SET(0);
n = SSL_read(conn->ssl, ptr, len);
err = SSL_get_error(conn->ssl, n);
switch (err)
@@ -409,6 +410,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
DISABLE_SIGPIPE(conn, spinfo, return -1);
+ SOCK_ERRNO_SET(0);
n = SSL_write(conn->ssl, ptr, len);
err = SSL_get_error(conn->ssl, n);
switch (err)