Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 49008d6

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 dca992d commit 49008d6

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
@@ -1591,7 +1591,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
15911591
* syntax.
15921592
*/
15931593
keep_password =
1594-
((strcmp(user, PQuser(o_conn)) == 0) &&
1594+
(o_conn &&
1595+
(strcmp(user, PQuser(o_conn)) == 0) &&
15951596
(!host || strcmp(host, PQhost(o_conn)) == 0) &&
15961597
(strcmp(port, PQport(o_conn)) == 0) &&
15971598
!has_connection_string);
@@ -1718,7 +1719,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
17181719
/* Tell the user about the new connection */
17191720
if (!pset.quiet)
17201721
{
1721-
if (param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
1722+
if (!o_conn ||
1723+
param_is_newly_set(PQhost(o_conn), PQhost(pset.db)) ||
17221724
param_is_newly_set(PQport(o_conn), PQport(pset.db)))
17231725
{
17241726
char *host = PQhost(pset.db);

0 commit comments

Comments
 (0)