| From: | Fujii Masao <fujii(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix libpq crashes on malformed target_session_attrs query result |
| Date: | 2026-11-21 14:19:09 |
| Message-ID: | E1xUlvo-00000000e01-32c7@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)riseup(dot)net>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/f1743511-5fab-482e-94ec-1198ce18723e@riseup.net
Backpatch-through: 15
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/c2cd57f68cfe1ddc46aa33c5791322e217b4eae3
Modified Files
--------------
src/interfaces/libpq/fe-connect.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-11-21 14:22:07 | pgsql: pg_basebackup: Fix crashes on malformed server responses |
| Previous Message | Dean Rasheed | 2026-11-21 12:17:58 | pgsql: Fix stale source values in MERGE after a concurrent update. |