From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 3 Mar 2026 00:00:00 +0000 Subject: [PATCH] Fix bugs in pg_waldump tar archive support Fix several bugs introduced by the pg_waldump archive WAL reading feature: - pg_waldump.c: The error path for verify_directory() printed waldir (which is NULL when --path is used) instead of walpath. - archive_waldump.c: The error message for short reads had an operator precedence bug: (long long int) count - nbytes cast only count, not the subtraction result. Also reported nbytes (the requested amount) instead of count (the total file size) for the "of" portion. - archive_waldump.c: The "ignoring duplicate WAL" code path leaked fname (allocated via pnstrdup/palloc). Also changed the existing free(fname) to pfree(fname) for consistency. - pg_verifybackup.c: The rename from --wal-directory to --wal-path didn't preserve the old spelling as a backward-compatible alias. - pg_verifybackup.c: Fix double space before "Or" in --wal-path error hint message. --- diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c index 935ab8fafa8..b0b764913cf 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -131,6 +131,7 @@ main(int argc, char **argv) {"quiet", no_argument, NULL, 'q'}, {"skip-checksums", no_argument, NULL, 's'}, {"wal-path", required_argument, NULL, 'w'}, + {"wal-directory", required_argument, NULL, 'w'}, {NULL, 0, NULL, 0} }; @@ -376,7 +377,7 @@ main(int argc, char **argv) else { pg_log_error("WAL archive not found"); - pg_log_error_hint("Specify the correct path using the option -w/--wal-path. " + pg_log_error_hint("Specify the correct path using the option -w/--wal-path. " "Or you must use -n/--no-parse-wal when verifying a tar-format backup."); exit(1); } diff --git a/src/bin/pg_waldump/archive_waldump.c b/src/bin/pg_waldump/archive_waldump.c index c5a4485b5b1..1479efe61f5 100644 --- a/src/bin/pg_waldump/archive_waldump.c +++ b/src/bin/pg_waldump/archive_waldump.c @@ -344,8 +344,8 @@ read_archive_wal_page(XLogDumpPrivate *privateInfo, XLogRecPtr targetPagePtr, read_archive_file(privateInfo, READ_CHUNK_SIZE) == 0) pg_fatal("could not read file \"%s\" from archive \"%s\": read %lld of %lld", fname, privateInfo->archive_name, - (long long int) count - nbytes, - (long long int) nbytes); + (long long int) (count - nbytes), + (long long int) count); } } @@ -664,7 +664,7 @@ astreamer_waldump_content(astreamer *streamer, astreamer_member *member, privateInfo->start_segno > segno || privateInfo->end_segno < segno) { - free(fname); + pfree(fname); break; } } @@ -680,6 +680,7 @@ astreamer_waldump_content(astreamer *streamer, astreamer_member *member, { pg_log_warning("ignoring duplicate WAL \"%s\" found in archive \"%s\"", member->pathname, privateInfo->archive_name); + pfree(fname); break; } diff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c index 114969217d8..4b438b53ead 100644 --- a/src/bin/pg_waldump/pg_waldump.c +++ b/src/bin/pg_waldump/pg_waldump.c @@ -1223,7 +1223,7 @@ main(int argc, char **argv) /* validate path points to directory */ else if (!verify_directory(walpath)) { - pg_log_error("could not open directory \"%s\": %m", waldir); + pg_log_error("could not open directory \"%s\": %m", walpath); goto bad_argument; } }