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

Commit25fe5ac

Browse files
committed
Fix bugs in libpq's management of GSS encryption state.
GSS-related resources should be cleaned up in pqDropConnection,not freePGconn, else the wrong things happen when resettinga connection or trying to switch to a different server.It's also critical to reset conn->gssenc there.During connection setup, initialize conn->try_gss at the correctplace, else switching to a different server won't work right.Remove now-redundant cleanup of GSS resources around one (and, forsome reason, only one) pqDropConnection call in connectDBStart.Per report from Kyotaro Horiguchi that psql would freeze up,rather than successfully resetting a GSS-encrypted connectionafter a server restart.This is YA oversight in commitb0b39f7, so back-patch to v12.Discussion:https://postgr.es/m/20200710.173803.435804731896516388.horikyota.ntt@gmail.com
1 parent8d2ed66 commit25fe5ac

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

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

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ pqDropConnection(PGconn *conn, bool flushInput)
477477
{
478478
OM_uint32min_s;
479479

480+
if (conn->gcred!=GSS_C_NO_CREDENTIAL)
481+
{
482+
gss_release_cred(&min_s,&conn->gcred);
483+
conn->gcred=GSS_C_NO_CREDENTIAL;
484+
}
480485
if (conn->gctx)
481486
gss_delete_sec_context(&min_s,&conn->gctx,GSS_C_NO_BUFFER);
482487
if (conn->gtarg_nam)
@@ -496,6 +501,7 @@ pqDropConnection(PGconn *conn, bool flushInput)
496501
free(conn->gss_ResultBuffer);
497502
conn->gss_ResultBuffer=NULL;
498503
}
504+
conn->gssenc= false;
499505
}
500506
#endif
501507
#ifdefENABLE_SSPI
@@ -2027,11 +2033,6 @@ connectDBStart(PGconn *conn)
20272033
*/
20282034
resetPQExpBuffer(&conn->errorMessage);
20292035

2030-
#ifdefENABLE_GSS
2031-
if (conn->gssencmode[0]=='d')/* "disable" */
2032-
conn->try_gss= false;
2033-
#endif
2034-
20352036
/*
20362037
* Set up to try to connect to the first host. (Setting whichhost = -1 is
20372038
* a bit of a cheat, but PQconnectPoll will advance it to 0 before
@@ -2468,6 +2469,9 @@ PQconnectPoll(PGconn *conn)
24682469
conn->allow_ssl_try= (conn->sslmode[0]!='d');/* "disable" */
24692470
conn->wait_ssl_try= (conn->sslmode[0]=='a');/* "allow" */
24702471
#endif
2472+
#ifdefENABLE_GSS
2473+
conn->try_gss= (conn->gssencmode[0]!='d');/* "disable" */
2474+
#endif
24712475

24722476
reset_connection_state_machine= false;
24732477
need_new_connection= true;
@@ -3349,12 +3353,8 @@ PQconnectPoll(PGconn *conn)
33493353
*/
33503354
if (conn->gssenc&&conn->gssencmode[0]=='p')
33513355
{
3352-
OM_uint32minor;
3353-
33543356
/* postmaster expects us to drop the connection */
33553357
conn->try_gss= false;
3356-
conn->gssenc= false;
3357-
gss_delete_sec_context(&minor,&conn->gctx,NULL);
33583358
pqDropConnection(conn, true);
33593359
conn->status=CONNECTION_NEEDED;
33603360
gotokeep_going;
@@ -3906,9 +3906,6 @@ makeEmptyPGconn(void)
39063906
conn->verbosity=PQERRORS_DEFAULT;
39073907
conn->show_context=PQSHOW_CONTEXT_ERRORS;
39083908
conn->sock=PGINVALID_SOCKET;
3909-
#ifdefENABLE_GSS
3910-
conn->try_gss= true;
3911-
#endif
39123909

39133910
/*
39143911
* We try to send at least 8K at a time, which is the usual size of pipe
@@ -4065,22 +4062,6 @@ freePGconn(PGconn *conn)
40654062
free(conn->gsslib);
40664063
if (conn->connip)
40674064
free(conn->connip);
4068-
#ifdefENABLE_GSS
4069-
if (conn->gcred!=GSS_C_NO_CREDENTIAL)
4070-
{
4071-
OM_uint32minor;
4072-
4073-
gss_release_cred(&minor,&conn->gcred);
4074-
conn->gcred=GSS_C_NO_CREDENTIAL;
4075-
}
4076-
if (conn->gctx)
4077-
{
4078-
OM_uint32minor;
4079-
4080-
gss_delete_sec_context(&minor,&conn->gctx,GSS_C_NO_BUFFER);
4081-
conn->gctx=NULL;
4082-
}
4083-
#endif
40844065
/* Note that conn->Pfdebug is not ours to close or free */
40854066
if (conn->last_query)
40864067
free(conn->last_query);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp