From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pg_basebackup: Fix crashes on malformed server responses
Date: Sat, 21 Nov 2026 14:22:07 +0000
Message-ID: <E1xUlyg-00000000e43-1IIW@gemulon.postgresql.org> (raw)
pg_basebackup: Fix crashes on malformed server responses
pg_basebackup could crash when a server returned replication command
results with missing rows or columns.
This happened because pg_basebackup checked the row counts of the
BASE_BACKUP results but not the column counts before reading the backup
start and end positions and tablespace information. Its WAL streaming
code checked the row and column counts of TIMELINE_HISTORY results,
but only logged a warning on a mismatch and continued processing.
These omissions allowed NULL pointers returned by PQgetvalue() for
missing fields to reach string and numeric conversion functions.
Fix this by requiring at least one column in the backup start and end
results and at least three columns in the tablespace header before
accessing their values. Also report an error, release the result, and
stop the current WAL streaming attempt if a TIMELINE_HISTORY response
does not contain exactly one row and two columns. The latter change
also fixes the same crash in pg_receivewal, which shares this WAL
streaming code.
Backpatch to all supported versions.
Author: s1ko <s1ko@riseup.net>
Author: 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_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/0c539dcd64045570e857aeb427fbe152a59b7502
Modified Files
--------------
src/bin/pg_basebackup/pg_basebackup.c | 16 +++++++++-------
src/bin/pg_basebackup/receivelog.c | 6 ++++--
2 files changed, 13 insertions(+), 9 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: pg_basebackup: Fix crashes on malformed server responses
In-Reply-To: <E1xUlyg-00000000e43-1IIW@gemulon.postgresql.org>
References: <E1xUlyg-00000000e43-1IIW@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