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

Commit42de04f

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 parent431b638 commit42de04f

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

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

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,16 +1865,19 @@ PQconnectPoll(PGconn *conn)
18651865
/* should not happen really */
18661866
returnPGRES_POLLING_READING;
18671867
}
1868-
/* mark byte consumed */
1869-
conn->inStart=conn->inCursor;
18701868
if (SSLok=='S')
18711869
{
1870+
/* mark byte consumed */
1871+
conn->inStart=conn->inCursor;
18721872
/* Set up global SSL state if required */
18731873
if (pqsecure_initialize(conn)!=0)
18741874
gotoerror_return;
18751875
}
18761876
elseif (SSLok=='N')
18771877
{
1878+
/* mark byte consumed */
1879+
conn->inStart=conn->inCursor;
1880+
/* OK to do without SSL? */
18781881
if (conn->sslmode[0]=='r'||/* "require" */
18791882
conn->sslmode[0]=='v')/* "verify-ca" or
18801883
* "verify-full" */
@@ -1891,29 +1894,17 @@ PQconnectPoll(PGconn *conn)
18911894
}
18921895
elseif (SSLok=='E')
18931896
{
1894-
/* Received error - probably protocol mismatch */
1895-
if (conn->Pfdebug)
1896-
fprintf(conn->Pfdebug,"received error from server, attempting fallback to pre-7.0\n");
1897-
if (conn->sslmode[0]=='r'||/* "require" */
1898-
conn->sslmode[0]=='v')/* "verify-ca" or
1899-
* "verify-full" */
1900-
{
1901-
/* Require SSL, but server is too old */
1902-
appendPQExpBuffer(&conn->errorMessage,
1903-
libpq_gettext("server does not support SSL, but SSL was required\n"));
1904-
gotoerror_return;
1905-
}
1906-
/* Otherwise, try again without SSL */
1907-
conn->allow_ssl_try= false;
1908-
/* Assume it ain't gonna handle protocol 3, either */
1909-
conn->pversion=PG_PROTOCOL(2,0);
1910-
/* Must drop the old connection */
1911-
closesocket(conn->sock);
1912-
conn->sock=-1;
1913-
conn->status=CONNECTION_NEEDED;
1914-
/* Discard any unread/unsent data */
1915-
conn->inStart=conn->inCursor=conn->inEnd=0;
1916-
conn->outCount=0;
1897+
/*
1898+
* Server failure of some sort, such as failure to
1899+
* fork a backend process. We need to process and
1900+
* report the error message, which might be formatted
1901+
* according to either protocol 2 or protocol 3.
1902+
* Rather than duplicate the code for that, we flip
1903+
* into AWAITING_RESPONSE state and let the code there
1904+
* deal with it. Note we have *not* consumed the "E"
1905+
* byte here.
1906+
*/
1907+
conn->status=CONNECTION_AWAITING_RESPONSE;
19171908
gotokeep_going;
19181909
}
19191910
else
@@ -2148,8 +2139,7 @@ PQconnectPoll(PGconn *conn)
21482139
* then do a non-SSL retry
21492140
*/
21502141
if (conn->sslmode[0]=='p'/* "prefer" */
2151-
&&conn->ssl
2152-
&&conn->allow_ssl_try/* redundant? */
2142+
&&conn->allow_ssl_try
21532143
&& !conn->wait_ssl_try)/* redundant? */
21542144
{
21552145
/* only retry once */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp