Skip to content

Commit e135c3d

Browse files
committed
Fix null pointer dereference in "\c" psql command.
The psql crash happened when no current connection existed. (The second new check is optional given today's undocumented NULL argument handling in PQhost() etc.) Back-patch to 9.0 (all supported versions).
1 parent 3b14a17 commit e135c3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bin/psql/command.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
17531753
* positional syntax.
17541754
*/
17551755
keep_password =
1756-
((strcmp(user, PQuser(o_conn)) == 0) &&
1756+
(o_conn &&
1757+
(strcmp(user, PQuser(o_conn)) == 0) &&
17571758
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
17581759
(strcmp(port, PQport(o_conn)) == 0) &&
17591760
!has_connection_string);
@@ -1880,7 +1881,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
18801881
/* Tell the user about the new connection */
18811882
if (!pset.quiet)
18821883
{
1883-
if (param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
1884+
if (!o_conn ||
1885+
param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
18841886
param_is_newly_set(PQport(o_conn), PQport(pset.db)))
18851887
{
18861888
char *host = PQhost(pset.db);

0 commit comments

Comments
 (0)