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

Commit bb9237a

Browse files
committed
Add missing bad-PGconn guards in libpq entry points.
There's a convention that externally-visible libpq functions should check for a NULL PGconn pointer, and fail gracefully instead of crashing. PQflush() and PQisnonblocking() didn't get that memo though. Also add a similar check to PQdefaultSSLKeyPassHook_OpenSSL; while it's not clear that ordinary usage could reach that with a null conn pointer, it's cheap enough to check, so let's be consistent. Daniele Varrazzo and Tom Lane Discussion: https://postgr.es/m/CA+mi_8Zm_mVVyW1iNFgyMd9Oh0Nv8-F+7Y3-BqwMgTMHuo_h2Q@mail.gmail.com
1 parent 1c5818b commit bb9237a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,6 +3917,8 @@ PQsetnonblocking(PGconn *conn, int arg)
39173917
int
39183918
PQisnonblocking(const PGconn *conn)
39193919
{
3920+
if (!conn || conn->status == CONNECTION_BAD)
3921+
return false;
39203922
return pqIsnonblocking(conn);
39213923
}
39223924

@@ -3936,6 +3938,8 @@ PQisthreadsafe(void)
39363938
int
39373939
PQflush(PGconn *conn)
39383940
{
3941+
if (!conn || conn->status == CONNECTION_BAD)
3942+
return -1;
39393943
return pqFlush(conn);
39403944
}
39413945

src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ my_SSL_set_fd(PGconn *conn, int fd)
19381938
int
19391939
PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
19401940
{
1941-
if (conn->sslpassword)
1941+
if (conn && conn->sslpassword)
19421942
{
19431943
if (strlen(conn->sslpassword) + 1 > size)
19441944
fprintf(stderr, libpq_gettext("WARNING: sslpassword truncated\n"));

0 commit comments

Comments
 (0)