Re: BUG #17625: In PG15 PQsslAttribute returns different values than PG14 when SSL is not in use for the connection - Mailing list pgsql-bugs

I wrote:
> AFAICS that behavioral change is deliberate: for the single case
> of inquiring about "library", PQsslAttribute now tells you which
> SSL implementation libpq *can* use, not which one it's actually
> using on a given connection.  I'm not sure that this is a great
> definition, since it's so unlike the behavior for other attributes.

Actually, wait a minute: both the documentation and the commit
message claim the new behavior is something different than what it
actually is.  The intention seems to have been to change the
behavior only for the conn == NULL case.  So maybe we need to
fix it as attached.  This'd still be broken for the
multiple-libraries scenario, but I admit that that's pretty
hypothetical.

            regards, tom lane

diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index aea4661736..e2eace2bc6 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -1745,14 +1745,18 @@ PQsslAttributeNames(PGconn *conn)
 const char *
 PQsslAttribute(PGconn *conn, const char *attribute_name)
 {
-    if (strcmp(attribute_name, "library") == 0)
-        return "OpenSSL";
-
     if (!conn)
+    {
+        if (strcmp(attribute_name, "library") == 0)
+            return "OpenSSL";
         return NULL;
+    }
     if (conn->ssl == NULL)
         return NULL;

+    if (strcmp(attribute_name, "library") == 0)
+        return "OpenSSL";
+
     if (strcmp(attribute_name, "key_bits") == 0)
     {
         static char sslbits_str[12];

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: [Bug][Ver 11]: Generic query plan selected is worse than custom query plan
Next
From: Heath Lord
Date:
Subject: Re: BUG #17625: In PG15 PQsslAttribute returns different values than PG14 when SSL is not in use for the connection