From 482ed836f7324ec558c8c6164659965ffff61de4 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Thu, 12 Dec 2002 22:42:39 +0000
Subject: [PATCH] Check SSL_get_error() value SSL_ERROR_SYSCALL to see if
 SSL_read() returned -1, per SSL_get_error() documentation.

Nathan Mueller
---
 src/backend/libpq/be-secure.c    | 12 +++++++++---
 src/interfaces/libpq/fe-secure.c |  8 +++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index 7973f2a05b0..fcbef04b670 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.16 2002/11/07 18:45:51 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.17 2002/12/12 22:42:39 momjian Exp $
  *
  *	  Since the server static private key ($DataDir/server.key)
  *	  will normally be stored unencrypted so that the database
@@ -288,7 +288,10 @@ secure_read(Port *port, void *ptr, size_t len)
 			case SSL_ERROR_WANT_READ:
 				break;
 			case SSL_ERROR_SYSCALL:
-				elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
+				if (n == -1)
+					elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
+				else
+					strerror(errno));
 				break;
 			case SSL_ERROR_SSL:
 				elog(ERROR, "SSL error: %s", SSLerrmessage());
@@ -337,7 +340,10 @@ secure_write(Port *port, const void *ptr, size_t len)
 			case SSL_ERROR_WANT_WRITE:
 				break;
 			case SSL_ERROR_SYSCALL:
-				elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
+				if (n == -1)
+					elog(ERROR, "SSL SYSCALL error: %s", strerror(errno));
+				else
+					strerror(errno));
 				break;
 			case SSL_ERROR_SSL:
 				elog(ERROR, "SSL error: %s", SSLerrmessage());
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index c32697f0aab..b0cec2608a5 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.16 2002/11/07 18:45:51 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.17 2002/12/12 22:42:39 momjian Exp $
  *
  * NOTES
  *	  The client *requires* a valid server certificate.  Since
@@ -270,7 +270,8 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
 			case SSL_ERROR_WANT_READ:
 				break;
 			case SSL_ERROR_SYSCALL:
-				printfPQExpBuffer(&conn->errorMessage,
+				if (n == -1)
+					printfPQExpBuffer(&conn->errorMessage,
 								libpq_gettext("SSL SYSCALL error: %s\n"),
 								  SOCK_STRERROR(SOCK_ERRNO));
 				break;
@@ -315,7 +316,8 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
 			case SSL_ERROR_WANT_WRITE:
 				break;
 			case SSL_ERROR_SYSCALL:
-				printfPQExpBuffer(&conn->errorMessage,
+				if (n == -1)
+					printfPQExpBuffer(&conn->errorMessage,
 								libpq_gettext("SSL SYSCALL error: %s\n"),
 								  SOCK_STRERROR(SOCK_ERRNO));
 				break;
-- 
GitLab