1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

pg_resetwal: Fix handling of commit timestamp XIDs

The help text for -c option documents that zero for either transaction
ID means to leave the corresponding value unchanged.  Commit
978cf02bb8 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 commit
636c1914b4, which intended to reject negative and out-of-range
arguments.

Author: Chao Li <lic@highgo.com>
Discussion: https://www.postgresql.org/message-id/F61E486B-746B-42F3-A532-B8D4F1519583@gmail.com
Backpatch-through: 19
This commit is contained in:
Heikki Linnakangas
2026-09-29 16:24:21 +03:00
parent ecd840a087
commit f1e60e0eb5

View File

@@ -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)