Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 80a0567

Browse files
committed
Fix bogus behavior of PQsslAttribute(conn, "library").
Commit ebc8b7d intended to change the behavior of PQsslAttribute(NULL, "library"), but accidentally also changed what happens with a non-NULL conn pointer. Undo that so that only the intended behavior change happens. Clarify some associated documentation. Per bug #17625 from Heath Lord. Back-patch to v15. Discussion: https://postgr.es/m/17625-fc47c78b7d71b534@postgresql.org
1 parent 551aa6b commit 80a0567

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

doc/src/sgml/libpq.sgml

+22-14
Original file line numberDiff line numberDiff line change
@@ -2514,8 +2514,9 @@ const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
25142514

25152515
<para>
25162516
The list of available attributes varies depending on the SSL library
2517-
being used, and the type of connection. If an attribute is not
2518-
available, returns NULL.
2517+
being used and the type of connection. Returns NULL if the connection
2518+
does not use SSL or the specified attribute name is not defined for the
2519+
library in use.
25192520
</para>
25202521

25212522
<para>
@@ -2574,12 +2575,15 @@ const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
25742575

25752576
<para>
25762577
As a special case, the <literal>library</literal> attribute may be
2577-
queried without an existing connection by passing NULL as the
2578-
<literal>conn</literal> argument. The historical behavior was to return
2579-
NULL for any attribute when a NULL <literal>conn</literal> was provided;
2580-
client programs needing to differentiate between the newer and older
2581-
implementations may check the
2582-
<literal>LIBPQ_HAS_SSL_LIBRARY_DETECTION</literal> feature macro.
2578+
queried without a connection by passing NULL as
2579+
the <literal>conn</literal> argument. The result will be the default
2580+
SSL library name, or NULL if <application>libpq</application> was
2581+
compiled without any SSL support. (Prior
2582+
to <productname>PostgreSQL</productname> version 15, passing NULL as
2583+
the <literal>conn</literal> argument always resulted in NULL.
2584+
Client programs needing to differentiate between the newer and older
2585+
implementations of this case may check the
2586+
<literal>LIBPQ_HAS_SSL_LIBRARY_DETECTION</literal> feature macro.)
25832587
</para>
25842588
</listitem>
25852589
</varlistentry>
@@ -2588,7 +2592,8 @@ const char *PQsslAttribute(const PGconn *conn, const char *attribute_name);
25882592
<term><function>PQsslAttributeNames</function><indexterm><primary>PQsslAttributeNames</primary></indexterm></term>
25892593
<listitem>
25902594
<para>
2591-
Return an array of SSL attribute names available. The array is terminated by a NULL pointer.
2595+
Returns an array of SSL attribute names available.
2596+
The array is terminated by a NULL pointer.
25922597
<synopsis>
25932598
const char * const * PQsslAttributeNames(const PGconn *conn);
25942599
</synopsis>
@@ -2600,17 +2605,20 @@ const char * const * PQsslAttributeNames(const PGconn *conn);
26002605
<term><function>PQsslStruct</function><indexterm><primary>PQsslStruct</primary></indexterm></term>
26012606
<listitem>
26022607
<para>
2603-
Return a pointer to an SSL-implementation-specific object describing
2604-
the connection.
2608+
Returns a pointer to an SSL-implementation-specific object describing
2609+
the connection. Returns NULL if the connection is not encrypted
2610+
or the requested type of object is not available from the connection's
2611+
SSL implementation.
26052612
<synopsis>
26062613
void *PQsslStruct(const PGconn *conn, const char *struct_name);
26072614
</synopsis>
26082615
</para>
26092616
<para>
26102617
The struct(s) available depend on the SSL implementation in use.
26112618
For <productname>OpenSSL</productname>, there is one struct,
2612-
available under the name "OpenSSL", and it returns a pointer to the
2613-
<productname>OpenSSL</productname> <literal>SSL</literal> struct.
2619+
available under the name <literal>OpenSSL</literal>,
2620+
and it returns a pointer to
2621+
<productname>OpenSSL</productname>'s <literal>SSL</literal> struct.
26142622
To use this function, code along the following lines could be used:
26152623
<programlisting><![CDATA[
26162624
#include <libpq-fe.h>
@@ -2643,7 +2651,7 @@ void *PQsslStruct(const PGconn *conn, const char *struct_name);
26432651
<listitem>
26442652
<para>
26452653
<indexterm><primary>SSL</primary><secondary sortas="libpq">in libpq</secondary></indexterm>
2646-
Returns the SSL structure used in the connection, or null
2654+
Returns the SSL structure used in the connection, or NULL
26472655
if SSL is not in use.
26482656

26492657
<synopsis>

src/interfaces/libpq/fe-secure-openssl.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -1745,14 +1745,21 @@ PQsslAttributeNames(PGconn *conn)
17451745
const char *
17461746
PQsslAttribute(PGconn *conn, const char *attribute_name)
17471747
{
1748-
if (strcmp(attribute_name, "library") == 0)
1749-
return "OpenSSL";
1750-
17511748
if (!conn)
1749+
{
1750+
/* PQsslAttribute(NULL, "library") reports the default SSL library */
1751+
if (strcmp(attribute_name, "library") == 0)
1752+
return "OpenSSL";
17521753
return NULL;
1754+
}
1755+
1756+
/* All attributes read as NULL for a non-encrypted connection */
17531757
if (conn->ssl == NULL)
17541758
return NULL;
17551759

1760+
if (strcmp(attribute_name, "library") == 0)
1761+
return "OpenSSL";
1762+
17561763
if (strcmp(attribute_name, "key_bits") == 0)
17571764
{
17581765
static char sslbits_str[12];

0 commit comments

Comments
 (0)