From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix libpq crashes on malformed target_session_attrs query result
Date: Sat, 21 Nov 2026 14:19:09 +0000
Message-ID: <E1xUlvo-00000000e04-38ko@gemulon.postgresql.org> (raw)
Fix libpq crashes on malformed target_session_attrs query results
Applications using libpq could crash during connection establishment
when a server returned an unexpected result for an internal query used
to check target_session_attrs.
This happened because libpq checked that the result contained one row,
but did not check the column count before reading the first column.
A result with one row and no columns caused PQgetvalue() to return NULL,
which was then passed to strncmp().
Fix this by requiring exactly one column in the results of SHOW
transaction_read_only and SELECT pg_catalog.pg_is_in_recovery().
Malformed results now follow the existing error path, rejecting the
connection attempt to that host and trying the next host, if any.
Backpatch to all supported versions.
Author: s1ko <s1ko@riseup.net>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/f1743511-5fab-482e-94ec-1198ce18723e@riseup.net
Backpatch-through: 15
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/42fa657db316e033ca5b30a4ac0bf69835b70ab8
Modified Files
--------------
src/interfaces/libpq/fe-connect.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: fujii@postgresql.org
Subject: Re: pgsql: Fix libpq crashes on malformed target_session_attrs query result
In-Reply-To: <E1xUlvo-00000000e04-38ko@gemulon.postgresql.org>
References: <E1xUlvo-00000000e04-38ko@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox