Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 39a9496

Browse files
committed
Fix some more problems with testing error returns from SSL.
1 parent 5c15cb4 commit 39a9496

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
2525
* IDENTIFICATION
26-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.100 2003/08/04 02:40:17 momjian Exp $
26+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.101 2003/08/04 17:25:14 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -648,7 +648,18 @@ pqReadData(PGconn *conn)
648648
* file is ready. Grumble. Fortunately, we don't expect this path to
649649
* be taken much, since in normal practice we should not be trying to
650650
* read data unless the file selected for reading already.
651+
*
652+
* In SSL mode it's even worse: SSL_read() could say WANT_READ and then
653+
* data could arrive before we make the pqReadReady() test. So we must
654+
* play dumb and assume there is more data, relying on the SSL layer to
655+
* detect true EOF.
651656
*/
657+
658+
#ifdef USE_SSL
659+
if (conn->ssl)
660+
return 0;
661+
#endif
662+
652663
switch (pqReadReady(conn))
653664
{
654665
case 0:

src/interfaces/libpq/fe-secure.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.28 2003/08/04 02:40:20 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.29 2003/08/04 17:25:14 tgl Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -308,23 +308,27 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
308308
libpq_gettext("SSL SYSCALL error: %s\n"),
309309
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
310310
else
311+
{
311312
printfPQExpBuffer(&conn->errorMessage,
312313
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
313314

315+
SOCK_ERRNO = ECONNRESET;
316+
n = -1;
317+
}
314318
break;
315319
}
316320
case SSL_ERROR_SSL:
317321
printfPQExpBuffer(&conn->errorMessage,
318322
libpq_gettext("SSL error: %s\n"), SSLerrmessage());
319323
/* fall through */
320324
case SSL_ERROR_ZERO_RETURN:
321-
pqsecure_close(conn);
322325
SOCK_ERRNO = ECONNRESET;
323326
n = -1;
324327
break;
325328
default:
326329
printfPQExpBuffer(&conn->errorMessage,
327330
libpq_gettext("Unknown SSL error code\n"));
331+
n = -1;
328332
break;
329333
}
330334
}
@@ -376,22 +380,26 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
376380
libpq_gettext("SSL SYSCALL error: %s\n"),
377381
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
378382
else
383+
{
379384
printfPQExpBuffer(&conn->errorMessage,
380385
libpq_gettext("SSL SYSCALL error: EOF detected\n"));
386+
SOCK_ERRNO = ECONNRESET;
387+
n = -1;
388+
}
381389
break;
382390
}
383391
case SSL_ERROR_SSL:
384392
printfPQExpBuffer(&conn->errorMessage,
385393
libpq_gettext("SSL error: %s\n"), SSLerrmessage());
386394
/* fall through */
387395
case SSL_ERROR_ZERO_RETURN:
388-
pqsecure_close(conn);
389396
SOCK_ERRNO = ECONNRESET;
390397
n = -1;
391398
break;
392399
default:
393400
printfPQExpBuffer(&conn->errorMessage,
394401
libpq_gettext("Unknown SSL error code\n"));
402+
n = -1;
395403
break;
396404
}
397405
}

0 commit comments

Comments
 (0)