Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4717992

Browse files
committed
Instead of a bare recv() to read the server's response to an SSL
request packet, use pqReadData(). This has the same effect sinceconn->ssl isn't set yet and we aren't expecting more than one byte.The advantage is that we will correctly detect loss-of-connectioninstead of going into an infinite loop. Per report from Hannu Krosing.
1 parenta3f98d5 commit4717992

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.297 2005/01/0618:29:10 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.298 2005/01/0620:06:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1452,30 +1452,36 @@ PQconnectPoll(PGconn *conn)
14521452

14531453
/*
14541454
* On first time through, get the postmaster's response to
1455-
* our SSL negotiation packet.Be careful to read only
1456-
* one byte (if there's more, it could be SSL data).
1455+
* our SSL negotiation packet.
14571456
*/
14581457
if (conn->ssl==NULL)
14591458
{
1459+
/*
1460+
* We use pqReadData here since it has the logic to
1461+
* distinguish no-data-yet from connection closure.
1462+
* Since conn->ssl isn't set, a plain recv() will occur.
1463+
*/
14601464
charSSLok;
1461-
intnread;
1465+
intrdresult;
14621466

1463-
retry_ssl_read:
1464-
nread=recv(conn->sock,&SSLok,1,0);
1465-
if (nread<0)
1467+
rdresult=pqReadData(conn);
1468+
if (rdresult<0)
14661469
{
1467-
if (SOCK_ERRNO==EINTR)
1468-
/* Interrupted system call - just try again */
1469-
gotoretry_ssl_read;
1470-
1471-
printfPQExpBuffer(&conn->errorMessage,
1472-
libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"),
1473-
SOCK_STRERROR(SOCK_ERRNO,sebuf,sizeof(sebuf)));
1470+
/* errorMessage is already filled in */
14741471
gotoerror_return;
14751472
}
1476-
if (nread==0)
1473+
if (rdresult==0)
1474+
{
14771475
/* caller failed to wait for data */
14781476
returnPGRES_POLLING_READING;
1477+
}
1478+
if (pqGetc(&SSLok,conn)<0)
1479+
{
1480+
/* should not happen really */
1481+
returnPGRES_POLLING_READING;
1482+
}
1483+
/* mark byte consumed */
1484+
conn->inStart=conn->inCursor;
14791485
if (SSLok=='S')
14801486
{
14811487
/* Do one-time setup; this creates conn->ssl */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp