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 <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: 
https://postgr.es/m/caap6zks_3oh3yhhagk6vu+2v1c2hv4k6spruzl415r-gxjd...@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(-)

Reply via email to