From 4f468093055324036d9af8fdf421f1b32b77bc3d Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sun, 19 Jun 2022 22:07:20 +0100 Subject: [PATCH] valid_temp_time: simplify/correct overflow check the logic for trying to detect the maximum value of time_t was broken; since we target a lower maximum time anyway, just use that for the overflow check --- ircd/s_newconf.c | 4 +--- tests/misc.c | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ircd/s_newconf.c b/ircd/s_newconf.c index 6688c6ef..c755d6e3 100644 --- a/ircd/s_newconf.c +++ b/ircd/s_newconf.c @@ -687,8 +687,6 @@ valid_temp_time(const char *p) time_t result = 0; long current = 0; - time_t max_time = (uintmax_t) (~(time_t)0) >> 1; - while (*p) { char *endp; int mul; @@ -726,7 +724,7 @@ valid_temp_time(const char *p) current *= mul; - if (current > max_time - result) + if (current > MAX_TEMP_TIME - result) return MAX_TEMP_TIME; result += current; diff --git a/tests/misc.c b/tests/misc.c index e588266e..88e2c1e2 100644 --- a/tests/misc.c +++ b/tests/misc.c @@ -60,15 +60,14 @@ static void valid_temp_time_invalid(void) static void valid_temp_time_overflow(void) { - time_t max_time = (uintmax_t) (~(time_t)0) >> 1; char s[100]; time_t t; - snprintf(s, sizeof s, "%" PRIuMAX "m", (uintmax_t) max_time / 60 + 2); + snprintf(s, sizeof s, "%" PRIuMAX "m", UINTMAX_MAX / 60 + 2); t = valid_temp_time(s); is_int(52 * WEEK, t, MSG); - snprintf(s, sizeof s, "%" PRIuMAX "m%" PRIuMAX "m", (uintmax_t) max_time / 60 - 1, (uintmax_t) max_time / 60 - 1); + snprintf(s, sizeof s, "%" PRIuMAX "m%" PRIuMAX "m", UINTMAX_MAX / 60 - 1, UINTMAX_MAX / 60 - 1); t = valid_temp_time(s); is_int(52 * WEEK, t, MSG); }