From d21d61b96f7a4d89e4b2e7cc9b9a1ec3f642fa12 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Sun, 14 Apr 2024 23:02:43 +0300 Subject: [PATCH] Put back initialization of 'sslmode', to silence Coverity Coverity pointed out that the function checks for conn->sslmode != NULL, which implies that it might be NULL, but later we access it without a NULL-check anyway. It doesn't know that it is in fact always initialized earlier, in conninfo_add_defaults(), and hence the NULL-check is not necessary. However, there is a lot of distance between conninfo_add_defaults() and pqConnectOptions2(), so it's not surprising that it doesn't see that. Put back the initialization code, as it existed before commit 05fd30c0e7, to silence the warning. In the long run, I'd like to refactor the libpq options handling and initalization code. It seems silly to strdup() and copy strings, for things like sslmode that have a limited set of possible values; it should be an enum. But that's for another day. --- src/interfaces/libpq/fe-connect.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index bb66d71cc4..9db1700ffb 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1576,6 +1576,12 @@ pqConnectOptions2(PGconn *conn) } #endif } + else + { + conn->sslmode = strdup(DefaultSSLMode); + if (!conn->sslmode) + goto oom_error; + } /* * validate sslnegotiation option, default is "postgres" for the postgres