Skip to content

Commit e37e9a6

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 bcf7eb9 commit e37e9a6

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
@@ -3267,6 +3267,8 @@ PQsetnonblocking(PGconn *conn, int arg)
32673267
int
32683268
PQisnonblocking(const PGconn *conn)
32693269
{
3270+
if (!conn || conn->status == CONNECTION_BAD)
3271+
return false;
32703272
return pqIsnonblocking(conn);
32713273
}
32723274

@@ -3286,6 +3288,8 @@ PQisthreadsafe(void)
32863288
int
32873289
PQflush(PGconn *conn)
32883290
{
3291+
if (!conn || conn->status == CONNECTION_BAD)
3292+
return -1;
32893293
return pqFlush(conn);
32903294
}
32913295

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ my_SSL_set_fd(PGconn *conn, int fd)
17471747
int
17481748
PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn)
17491749
{
1750-
if (conn->sslpassword)
1750+
if (conn && conn->sslpassword)
17511751
{
17521752
if (strlen(conn->sslpassword) + 1 > size)
17531753
fprintf(stderr, libpq_gettext("WARNING: sslpassword truncated\n"));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy