summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-07-24 16:29:13 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-07-24 16:29:13 -0400
commitf9d466e53036b9bb4e075ebde754b90008cf80b2 (patch)
treefdcd170fe1e90845c4984d71bfd80963c924e8cf /src/interfaces/libpq/fe-misc.c
parentf9c0547aa205148cc62b692a99fde8c3f62bd058 (diff)
Improve libpq's error reporting for SSL failures.
In many cases, pqsecure_read/pqsecure_write set up useful error messages, which were then overwritten with useless ones by their callers. Fix this by defining the responsibility to set an error message to be entirely that of the lower-level function when using SSL. Back-patch to 8.3; the code is too different in 8.2 to be worth the trouble.
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 17dde4aecc4..02e011e1eb0 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -647,7 +647,9 @@ retry3:
if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed;
#endif
- printfPQExpBuffer(&conn->errorMessage,
+ /* in SSL mode, pqsecure_read set the error message */
+ if (conn->ssl == NULL)
+ printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1;
@@ -737,7 +739,9 @@ retry4:
if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed;
#endif
- printfPQExpBuffer(&conn->errorMessage,
+ /* in SSL mode, pqsecure_read set the error message */
+ if (conn->ssl == NULL)
+ printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return -1;
@@ -753,8 +757,10 @@ retry4:
* means the connection has been closed. Cope.
*/
definitelyFailed:
- printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext(
+ /* in SSL mode, pqsecure_read set the error message */
+ if (conn->ssl == NULL)
+ printfPQExpBuffer(&conn->errorMessage,
+ libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
@@ -831,8 +837,10 @@ pqSendSome(PGconn *conn, int len)
#ifdef ECONNRESET
case ECONNRESET:
#endif
- printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext(
+ /* in SSL mode, pqsecure_write set the error message */
+ if (conn->ssl == NULL)
+ printfPQExpBuffer(&conn->errorMessage,
+ libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
@@ -849,7 +857,9 @@ pqSendSome(PGconn *conn, int len)
return -1;
default:
- printfPQExpBuffer(&conn->errorMessage,
+ /* in SSL mode, pqsecure_write set the error message */
+ if (conn->ssl == NULL)
+ printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send data to server: %s\n"),
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
/* We don't assume it's a fatal error... */