Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a28083

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 1a05596 commit 2a28083

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
@@ -3221,6 +3221,8 @@ PQsetnonblocking(PGconn *conn, int arg)
32213221
int
32223222
PQisnonblocking(const PGconn *conn)
32233223
{
3224+
if (!conn || conn->status == CONNECTION_BAD)
3225+
return false;
32243226
return pqIsnonblocking(conn);
32253227
}
32263228

@@ -3240,6 +3242,8 @@ PQisthreadsafe(void)
32403242
int
32413243
PQflush(PGconn *conn)
32423244
{
3245+
if (!conn || conn->status == CONNECTION_BAD)
3246+
return -1;
32433247
return pqFlush(conn);
32443248
}
32453249

0 commit comments

Comments
 (0)