From 2b12165b30c5a63d6ab4608ebdc8348b0c02cd3c Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Tue, 29 Sep 2026 13:23:55 +0800 Subject: [PATCH v1] pg_resetwal: Fix handling of commit timestamp XIDs The -c option documents that zero for either transaction ID means to leave the corresponding control file value unchanged. Commit 978cf02bb8c replaced the separate checks for the two values with a single flag indicating that the option was specified, causing zero to be written to the control file instead. Also parse the second transaction ID with strtouint32_strict(), like the first one. Using strtoul() there was an oversight in 636c1914b48, which intended to reject negative and out-of-range arguments. Author: Chao Li --- src/bin/pg_resetwal/pg_resetwal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index 41afc4c1316..634d966da9e 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -233,7 +233,7 @@ main(int argc, char *argv[]) pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } - newest_commit_ts_xid_val = strtoul(endptr + 1, &endptr2, 0); + newest_commit_ts_xid_val = strtouint32_strict(endptr + 1, &endptr2, 0); if (endptr2 == endptr + 1 || *endptr2 != '\0' || errno != 0) { pg_log_error("invalid argument for option %s", "-c"); @@ -482,8 +482,10 @@ main(int argc, char *argv[]) if (commit_ts_xids_given) { - ControlFile.checkPointCopy.oldestCommitTsXid = oldest_commit_ts_xid_val; - ControlFile.checkPointCopy.newestCommitTsXid = newest_commit_ts_xid_val; + if (oldest_commit_ts_xid_val != InvalidTransactionId) + ControlFile.checkPointCopy.oldestCommitTsXid = oldest_commit_ts_xid_val; + if (newest_commit_ts_xid_val != InvalidTransactionId) + ControlFile.checkPointCopy.newestCommitTsXid = newest_commit_ts_xid_val; } if (next_oid_given) -- 2.50.1 (Apple Git-155)