Skip to content

Commit fb147dc

Browse files
committed
If we're going to print unrecognized result codes from SSL_get_error
in open_client_SSL, surely we should do it everywhere. Also make message formatting conform to style guide.
1 parent fa6fa8e commit fb147dc

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/backend/libpq/be-secure.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.49 2004/09/09 00:59:31 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.50 2004/09/23 20:27:50 tgl Exp $
1515
*
1616
* Since the server static private key ($DataDir/server.key)
1717
* will normally be stored unencrypted so that the database
@@ -257,9 +257,12 @@ secure_read(Port *port, void *ptr, size_t len)
257257
#ifdef USE_SSL
258258
if (port->ssl)
259259
{
260+
int err;
261+
260262
rloop:
261263
n = SSL_read(port->ssl, ptr, len);
262-
switch (SSL_get_error(port->ssl, n))
264+
err = SSL_get_error(port->ssl, n);
265+
switch (err)
263266
{
264267
case SSL_ERROR_NONE:
265268
port->count += n;
@@ -293,8 +296,8 @@ secure_read(Port *port, void *ptr, size_t len)
293296
default:
294297
ereport(COMMERROR,
295298
(errcode(ERRCODE_PROTOCOL_VIOLATION),
296-
errmsg("unrecognized SSL error code %d",
297-
SSL_get_error(port->ssl, n))));
299+
errmsg("unrecognized SSL error code: %d",
300+
err)));
298301
n = -1;
299302
break;
300303
}
@@ -317,6 +320,8 @@ secure_write(Port *port, void *ptr, size_t len)
317320
#ifdef USE_SSL
318321
if (port->ssl)
319322
{
323+
int err;
324+
320325
if (port->count > RENEGOTIATION_LIMIT)
321326
{
322327
SSL_set_session_id_context(port->ssl, (void *) &SSL_context,
@@ -344,7 +349,8 @@ secure_write(Port *port, void *ptr, size_t len)
344349

345350
wloop:
346351
n = SSL_write(port->ssl, ptr, len);
347-
switch (SSL_get_error(port->ssl, n))
352+
err = SSL_get_error(port->ssl, n);
353+
switch (err)
348354
{
349355
case SSL_ERROR_NONE:
350356
port->count += n;
@@ -378,8 +384,8 @@ secure_write(Port *port, void *ptr, size_t len)
378384
default:
379385
ereport(COMMERROR,
380386
(errcode(ERRCODE_PROTOCOL_VIOLATION),
381-
errmsg("unrecognized SSL error code %d",
382-
SSL_get_error(port->ssl, n))));
387+
errmsg("unrecognized SSL error code: %d",
388+
err)));
383389
n = -1;
384390
break;
385391
}

src/interfaces/libpq/fe-secure.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.50 2004/09/23 13:20:45 momjian Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.51 2004/09/23 20:27:43 tgl Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -297,9 +297,12 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
297297
#ifdef USE_SSL
298298
if (conn->ssl)
299299
{
300+
int err;
301+
300302
rloop:
301303
n = SSL_read(conn->ssl, ptr, len);
302-
switch (SSL_get_error(conn->ssl, n))
304+
err = SSL_get_error(conn->ssl, n);
305+
switch (err)
303306
{
304307
case SSL_ERROR_NONE:
305308
break;
@@ -349,7 +352,8 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
349352
break;
350353
default:
351354
printfPQExpBuffer(&conn->errorMessage,
352-
libpq_gettext("unrecognized SSL error code\n"));
355+
libpq_gettext("unrecognized SSL error code: %d\n"),
356+
err);
353357
n = -1;
354358
break;
355359
}
@@ -380,8 +384,11 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
380384
#ifdef USE_SSL
381385
if (conn->ssl)
382386
{
387+
int err;
388+
383389
n = SSL_write(conn->ssl, ptr, len);
384-
switch (SSL_get_error(conn->ssl, n))
390+
err = SSL_get_error(conn->ssl, n);
391+
switch (err)
385392
{
386393
case SSL_ERROR_NONE:
387394
break;
@@ -429,7 +436,8 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
429436
break;
430437
default:
431438
printfPQExpBuffer(&conn->errorMessage,
432-
libpq_gettext("unrecognized SSL error code\n"));
439+
libpq_gettext("unrecognized SSL error code: %d\n"),
440+
err);
433441
n = -1;
434442
break;
435443
}
@@ -1020,6 +1028,7 @@ open_client_SSL(PGconn *conn)
10201028
if (r <= 0)
10211029
{
10221030
int err = SSL_get_error(conn->ssl, r);
1031+
10231032
switch (err)
10241033
{
10251034
case SSL_ERROR_WANT_READ:
@@ -1055,7 +1064,8 @@ open_client_SSL(PGconn *conn)
10551064

10561065
default:
10571066
printfPQExpBuffer(&conn->errorMessage,
1058-
libpq_gettext("unrecognized SSL error code (%d)\n"), err);
1067+
libpq_gettext("unrecognized SSL error code: %d\n"),
1068+
err);
10591069
close_SSL(conn);
10601070
return PGRES_POLLING_FAILED;
10611071
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy