]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Avoid overflow in MaybeRemoveOldWalSummaries().
authorNathan Bossart <nathan@postgresql.org>
Wed, 20 Mar 2024 18:31:58 +0000 (13:31 -0500)
committerNathan Bossart <nathan@postgresql.org>
Wed, 20 Mar 2024 18:31:58 +0000 (13:31 -0500)
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

src/backend/postmaster/walsummarizer.c
src/backend/utils/misc/guc_tables.c

index b412d0eb86627981a6a09c9c5c2eabfbfc6af869..0cd5080fa78c1c46a4676231a0145c8498bc2e56 100644 (file)
@@ -140,7 +140,7 @@ static XLogRecPtr redo_pointer_at_last_summary_removal = InvalidXLogRecPtr;
  * GUC parameters
  */
 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 XLogRecPtr GetLatestLSN(TimeLineID *tli);
@@ -1480,7 +1480,7 @@ MaybeRemoveOldWalSummaries(void)
         * Files should only be removed if the last modification time precedes the
         * 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. */
        wslist = GetWalSummaries(0, InvalidXLogRecPtr, InvalidXLogRecPtr);
index 57d9de4dd92deb3202fa6ff5f0be5f967b49882d..1e71e7db4a098f56e1f5092eabbb3f7e14465f83 100644 (file)
@@ -3293,9 +3293,9 @@ struct config_int ConfigureNamesInt[] =
                        GUC_UNIT_MIN,
                },
                &wal_summary_keep_time,
-               10 * 24 * 60,                   /* 10 days */
+               10 * HOURS_PER_DAY * MINS_PER_HOUR, /* 10 days */
                0,
-               INT_MAX,
+               INT_MAX / SECS_PER_MINUTE,
                NULL, NULL, NULL
        },