libpq: If ALPN is not used, make PQsslAttribute(conn, "alpn") == ""
authorHeikki Linnakangas <[email protected]>
Mon, 29 Apr 2024 09:26:46 +0000 (12:26 +0300)
committerHeikki Linnakangas <[email protected]>
Mon, 29 Apr 2024 09:26:46 +0000 (12:26 +0300)
The documentation says that PQsslAttribute(conn, "alpn") returns an
empty string if ALPN is not used, but the code actually returned
NULL. Fix the code to match the documentation.

Reported-by: Michael Paquier
Discussion: https://www.postgresql.org/message-id/[email protected]

src/bin/psql/command.c
src/interfaces/libpq/fe-secure-openssl.c

index 288c1a8c9357cf5822efa109118cf5627fe41ee5..fae5940b54e972f5f174cbf38429b3ac055be9dc 100644 (file)
@@ -3896,7 +3896,7 @@ printSSLInfo(void)
           protocol ? protocol : _("unknown"),
           cipher ? cipher : _("unknown"),
           (compression && strcmp(compression, "off") != 0) ? _("on") : _("off"),
-          alpn ? alpn : _("none"));
+          (alpn && alpn[0] != '\0') ? alpn : _("none"));
 }
 
 /*
index e7a4d006e195dc25974dbfb126b599586701d645..33362000d3c94d09a09ae048d7a9983092dc4e9a 100644 (file)
@@ -1837,7 +1837,7 @@ PQsslAttribute(PGconn *conn, const char *attribute_name)
 
        SSL_get0_alpn_selected(conn->ssl, &data, &len);
        if (data == NULL || len == 0 || len > sizeof(alpn_str) - 1)
-           return NULL;
+           return "";
        memcpy(alpn_str, data, len);
        alpn_str[len] = 0;
        return alpn_str;