1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

Avoid overflow in MaybeRemoveOldWalSummaries().

This commit limits the maximum value of wal_summary_keep_time to
INT_MAX / SECS_PER_MINUTE to avoid overflow when it is converted to
seconds.  In passing, use the HOURS_PER_DAY, MINS_PER_HOUR, and
SECS_PER_MINUTE macros in the code for this GUC instead of hard-
coding those values.

Discussion: https://postgr.es/m/20240314210010.GA3056455%40nathanxps13
This commit is contained in:
Nathan Bossart
2024-03-20 13:31:58 -05:00
parent 9acae56ce0
commit 80686761c4
2 changed files with 4 additions and 4 deletions

View File

@ -140,7 +140,7 @@ static XLogRecPtr redo_pointer_at_last_summary_removal = InvalidXLogRecPtr;
* GUC parameters * GUC parameters
*/ */
bool summarize_wal = false; bool summarize_wal = false;
int wal_summary_keep_time = 10 * 24 * 60; int wal_summary_keep_time = 10 * HOURS_PER_DAY * MINS_PER_HOUR;
static void WalSummarizerShutdown(int code, Datum arg); static void WalSummarizerShutdown(int code, Datum arg);
static XLogRecPtr GetLatestLSN(TimeLineID *tli); static XLogRecPtr GetLatestLSN(TimeLineID *tli);
@ -1480,7 +1480,7 @@ MaybeRemoveOldWalSummaries(void)
* Files should only be removed if the last modification time precedes the * Files should only be removed if the last modification time precedes the
* cutoff time we compute here. * cutoff time we compute here.
*/ */
cutoff_time = time(NULL) - 60 * wal_summary_keep_time; cutoff_time = time(NULL) - wal_summary_keep_time * SECS_PER_MINUTE;
/* Get all the summaries that currently exist. */ /* Get all the summaries that currently exist. */
wslist = GetWalSummaries(0, InvalidXLogRecPtr, InvalidXLogRecPtr); wslist = GetWalSummaries(0, InvalidXLogRecPtr, InvalidXLogRecPtr);

View File

@ -3293,9 +3293,9 @@ struct config_int ConfigureNamesInt[] =
GUC_UNIT_MIN, GUC_UNIT_MIN,
}, },
&wal_summary_keep_time, &wal_summary_keep_time,
10 * 24 * 60, /* 10 days */ 10 * HOURS_PER_DAY * MINS_PER_HOUR, /* 10 days */
0, 0,
INT_MAX, INT_MAX / SECS_PER_MINUTE,
NULL, NULL, NULL NULL, NULL, NULL
}, },