pgsql: Use pg_parse_lsn() for server-supplied LSNs

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use pg_parse_lsn() for server-supplied LSNs
Date: 2026-08-21 07:40:35
Message-ID: E1wxJre-00000001U9Z-2SJ4@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use pg_parse_lsn() for server-supplied LSNs

Commit d6bf0ab170 introduced pg_parse_lsn() to validate LSNs given on
the command line of pg_waldump, pg_recvlogical, and pg_receivewal.
The remaining sscanf("%X/%08X") call sites under src/bin parse LSNs
that arrive in server responses, timeline history files, and
backup_label files. sscanf() accepts several forms that pg_lsn input
rejects and can silently continue with a different location than the
input text: a first component wider than eight hex digits wraps
around, a wider second component is truncated, and leading
whitespace, signs, "0x" prefixes, and trailing characters are
consumed or ignored.

Convert those call sites as well. The two call sites that read a
location out of a longer line isolate it by temporarily terminating
the string at the next whitespace character, so that they can use
pg_parse_lsn() like the others. Each tool keeps its existing error
message.

Malformed metadata now fails with each tool's existing error instead
of silently proceeding with a different location. Two error paths
shift: pg_rewind's history-file parser now rejects trailing
characters attached to a switchpoint, which used to be ignored, and a
malformed backup_label location now fails pg_combinebackup's "could
not parse" check rather than its "improper terminator" check.

Author: Zexin Li <lizi(dot)openmind(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAAP6ZkS_3OH3yhhAGK6vu+2V1C2Hv4K6SpRuZL415R-gxjdTSg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f31d6fbc31d3b6901022e011942ac680d347d46a

Modified Files
--------------
src/bin/pg_basebackup/pg_basebackup.c | 16 ++++----------
src/bin/pg_basebackup/receivelog.c | 8 ++-----
src/bin/pg_basebackup/streamutil.c | 12 +++--------
src/bin/pg_combinebackup/backup_label.c | 24 +++++++++++----------
src/bin/pg_rewind/libpq_source.c | 7 ++-----
src/bin/pg_rewind/timeline.c | 37 ++++++++++++++++++++++++++-------
6 files changed, 53 insertions(+), 51 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Etsuro Fujita 2026-08-21 08:54:22 pgsql: Fix typos in comments.
Previous Message Richard Guo 2026-08-21 06:52:25 pgsql: Collect quals for outer-join reduction on demand