Skip to content

Commit c19024d

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 e2915af commit c19024d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,8 @@ PQsetnonblocking(PGconn *conn, int arg)
32683268
int
32693269
PQisnonblocking(const PGconn *conn)
32703270
{
3271+
if (!conn || conn->status == CONNECTION_BAD)
3272+
return false;
32713273
return pqIsnonblocking(conn);
32723274
}
32733275

@@ -3287,6 +3289,8 @@ PQisthreadsafe(void)
32873289
int
32883290
PQflush(PGconn *conn)
32893291
{
3292+
if (!conn || conn->status == CONNECTION_BAD)
3293+
return -1;
32903294
return pqFlush(conn);
32913295
}
32923296

0 commit comments

Comments
 (0)