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

Commitdaf9bdc

Browse files
committed
Fix PQport to never return NULL unless the connection is NULL.
This is the documented behavior, and it worked that way beforev10. However, addition of the connhost[] array created caseswhere conn->connhost[conn->whichhost].port is NULL. The restof libpq is careful to substitute DEF_PGPORT[_STR] for a nullor empty port string, but we failed to do so here, leading topossibly returning NULL. As of v18 that causes psql's \conninfocommand to segfault. Older psql versions avoid that, but it'spretty likely that other clients have trouble with this,so we'd better back-patch the fix.In stable branches, just revert to our historical behavior ofreturning an empty string when there was no user-given portspecification. However, it seems substantially more useful andindeed more correct to hand back DEF_PGPORT_STR in such cases,so let's make v18 and master do that.Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/CA+mi_8YTS8WPZPO0PAb2aaGLwHuQ0DEQRF0ZMnvWss4y9FwDYQ@mail.gmail.comBackpatch-through: 13
1 parentb8926a5 commitdaf9bdc

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7574,10 +7574,12 @@ PQport(const PGconn *conn)
75747574
if (!conn)
75757575
returnNULL;
75767576

7577-
if (conn->connhost!=NULL)
7577+
if (conn->connhost!=NULL&&
7578+
conn->connhost[conn->whichhost].port!=NULL&&
7579+
conn->connhost[conn->whichhost].port[0]!='\0')
75787580
returnconn->connhost[conn->whichhost].port;
75797581

7580-
return"";
7582+
returnDEF_PGPORT_STR;
75817583
}
75827584

75837585
/*

‎src/interfaces/libpq/libpq-int.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ typedef struct pg_conn_host
357357
pg_conn_host_typetype;/* type of host address */
358358
char*host;/* host name or socket path */
359359
char*hostaddr;/* host numeric IP address */
360-
char*port;/* port number (always provided) */
360+
char*port;/* port number (if NULL or empty, use
361+
* DEF_PGPORT[_STR]) */
361362
char*password;/* password for this host, read from the
362363
* password file; NULL if not sought or not
363364
* found in password file. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp