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

Commita2d9f94

Browse files
committed
Don't assume that "E" response to NEGOTIATE_SSL_CODE means pre-7.0 server.
These days, such a response is far more likely to signify a server-sideproblem, such as fork failure. Reporting "server does not support SSL"(in sslmode=require) could be quite misleading. But the results couldbe even worse in sslmode=prefer: if the problem was transient and thenext connection attempt succeeds, we'll have silently fallen back toprotocol version 2.0, possibly disabling features the user needs.Hence, it seems best to just eliminate the assumption that backing offto non-SSL/2.0 protocol is the way to recover from an "E" response, andinstead treat the server error the same as we would in non-SSL cases.I tested this change against a pre-7.0 server, and found that therewas a second logic bug in the "prefer" path: the test to decide whetherto make a fallback connection attempt assumed that we must have openedconn->ssl, which in fact does not happen given an "E" response. Afterfixing that, the code does indeed connect successfully to pre-7.0,as long as you didn't set sslmode=require. (If you did, you get"Unsupported frontend protocol", which isn't completely off basegiven the server certainly doesn't support SSL.)Since there seems no reason to believe that pre-7.0 servers exist anymorein the wild, back-patch to all supported branches.
1 parentbb42ad1 commita2d9f94

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

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

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,16 +1337,19 @@ PQconnectPoll(PGconn *conn)
13371337
/* should not happen really */
13381338
returnPGRES_POLLING_READING;
13391339
}
1340-
/* mark byte consumed */
1341-
conn->inStart=conn->inCursor;
13421340
if (SSLok=='S')
13431341
{
1342+
/* mark byte consumed */
1343+
conn->inStart=conn->inCursor;
13441344
/* Do one-time setup; this creates conn->ssl */
13451345
if (pqsecure_initialize(conn)==-1)
13461346
gotoerror_return;
13471347
}
13481348
elseif (SSLok=='N')
13491349
{
1350+
/* mark byte consumed */
1351+
conn->inStart=conn->inCursor;
1352+
/* OK to do without SSL? */
13501353
if (conn->sslmode[0]=='r')/* "require" */
13511354
{
13521355
/* Require SSL, but server does not want it */
@@ -1361,27 +1364,17 @@ PQconnectPoll(PGconn *conn)
13611364
}
13621365
elseif (SSLok=='E')
13631366
{
1364-
/* Received error - probably protocol mismatch */
1365-
if (conn->Pfdebug)
1366-
fprintf(conn->Pfdebug,"received error from server, attempting fallback to pre-7.0\n");
1367-
if (conn->sslmode[0]=='r')/* "require" */
1368-
{
1369-
/* Require SSL, but server is too old */
1370-
printfPQExpBuffer(&conn->errorMessage,
1371-
libpq_gettext("server does not support SSL, but SSL was required\n"));
1372-
gotoerror_return;
1373-
}
1374-
/* Otherwise, try again without SSL */
1375-
conn->allow_ssl_try= false;
1376-
/* Assume it ain't gonna handle protocol 3, either */
1377-
conn->pversion=PG_PROTOCOL(2,0);
1378-
/* Must drop the old connection */
1379-
closesocket(conn->sock);
1380-
conn->sock=-1;
1381-
conn->status=CONNECTION_NEEDED;
1382-
/* Discard any unread/unsent data */
1383-
conn->inStart=conn->inCursor=conn->inEnd=0;
1384-
conn->outCount=0;
1367+
/*
1368+
* Server failure of some sort, such as failure to
1369+
* fork a backend process. We need to process and
1370+
* report the error message, which might be formatted
1371+
* according to either protocol 2 or protocol 3.
1372+
* Rather than duplicate the code for that, we flip
1373+
* into AWAITING_RESPONSE state and let the code there
1374+
* deal with it. Note we have *not* consumed the "E"
1375+
* byte here.
1376+
*/
1377+
conn->status=CONNECTION_AWAITING_RESPONSE;
13851378
gotokeep_going;
13861379
}
13871380
else
@@ -1614,8 +1607,7 @@ PQconnectPoll(PGconn *conn)
16141607
* then do a non-SSL retry
16151608
*/
16161609
if (conn->sslmode[0]=='p'/* "prefer" */
1617-
&&conn->ssl
1618-
&&conn->allow_ssl_try/* redundant? */
1610+
&&conn->allow_ssl_try
16191611
&& !conn->wait_ssl_try)/* redundant? */
16201612
{
16211613
/* only retry once */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp