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 <[email protected]> Author: Chao Li <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4fe8b64dc69844d20e2952a1343097c83d6e0b1c Modified Files -------------- src/bin/pg_basebackup/pg_basebackup.c | 16 +++++++++------- src/bin/pg_basebackup/receivelog.c | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-)
