Skip to content

Commit c95d215

Browse files
committed
Fix fallback behavior when server sends an ERROR early at startup
With sslmode=prefer, the desired behavior is to completely fail the connection attempt, *not* fall back to a plaintext connection, if the server responds to the SSLRequest with an error ('E') response instead of rejecting SSL with an 'N' response. This was broken in commit 05fd30c. Reported-by: Jacob Champion Reviewed-by: Michael Paquier Discussion: https://www.postgresql.org/message-id/CAOYmi%2Bnwvu21mJ4DYKUa98HdfM_KZJi7B1MhyXtnsyOO-PB6Ww%40mail.gmail.com Backpatch-through: 17
1 parent 284c030 commit c95d215

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,12 @@ PQconnectPoll(PGconn *conn)
35213521
* byte here.
35223522
*/
35233523
conn->status = CONNECTION_AWAITING_RESPONSE;
3524+
3525+
/*
3526+
* Don't fall back to a plaintext connection after
3527+
* reading the error.
3528+
*/
3529+
conn->failed_enc_methods |= conn->allowed_enc_methods & (~conn->current_enc_method);
35243530
goto keep_going;
35253531
}
35263532
else
@@ -3612,6 +3618,13 @@ PQconnectPoll(PGconn *conn)
36123618
* into AWAITING_RESPONSE state and let the code there
36133619
* deal with it. Note we have *not* consumed the "E"
36143620
* byte here.
3621+
*
3622+
* Note that unlike on an error response to
3623+
* SSLRequest, we allow falling back to SSL or
3624+
* plaintext connection here. GSS support was
3625+
* introduced in PostgreSQL version 12, so an error
3626+
* response might mean that we are connecting to a
3627+
* pre-v12 server.
36153628
*/
36163629
conn->status = CONNECTION_AWAITING_RESPONSE;
36173630
goto keep_going;
@@ -3659,6 +3672,10 @@ PQconnectPoll(PGconn *conn)
36593672
}
36603673
else if (pollres == PGRES_POLLING_FAILED)
36613674
{
3675+
/*
3676+
* GSS handshake failed. We will retry with an SSL or
3677+
* plaintext connection, if permitted by the options.
3678+
*/
36623679
CONNECTION_FAILED();
36633680
}
36643681
/* Else, return POLLING_READING or POLLING_WRITING status */

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