Skip to content

Commit f79bea4

Browse files
committed
Fix crash in psql when attempting to reuse old connection
In a psql session, if the connection to the server is abruptly cut, the referenced connection would become NULL as of CheckConnection(). This could cause a hard crash with psql if attempting to connect by reusing the past connection's data because of a null-pointer dereference with either PQhost() or PQdb(). This issue is fixed by making sure that no reuse of the past connection is done if it does not exist. Issue has been introduced by 6e5f8d4, so backpatch down to 12. Reported-by: Hugh Wang Author: Michael Paquier Reviewed-by: Álvaro Herrera, Tom Lane Discussion: https://postgr.es/m/16330-b34835d83619e25d@postgresql.org Backpatch-through: 12
1 parent 6a50f1a commit f79bea4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/bin/psql/command.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,11 @@ do_connect(enum trivalue reuse_previous_specification,
29412941
reuse_previous = !has_connection_string;
29422942
break;
29432943
}
2944+
2945+
/* If the old connection does not exist, there is nothing to reuse. */
2946+
if (!o_conn)
2947+
reuse_previous = false;
2948+
29442949
/* Silently ignore arguments subsequent to a connection string. */
29452950
if (has_connection_string)
29462951
{

0 commit comments

Comments
 (0)