pgsql: pg_basebackup: Fix crashes on malformed server responses
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: /messages/by-id/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(-)