From ccb3f3937ea87a392b87233f1b2feb3d0eeeedf4 Mon Sep 17 00:00:00 2001 From: Angelo Gkaraleas Date: Sun, 21 Jul 2024 22:40:29 +0200 Subject: [PATCH] This pull requests completes fix of PR #12474 regarding an integer overflow in processTimeEvents of ae.c Although the major effect of maximizing the CPU usage was handled, the integer overflow could still happen for calculated next periods > INT_MAX resulting in wrong calculation of the next period of the time event To address this, prototype was changed to return a long long in order to prevent the above overflow --- src/ae.c | 2 +- src/ae.h | 2 +- src/evict.c | 2 +- src/module.c | 2 +- src/redis-benchmark.c | 5 ++--- src/server.c | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ae.c b/src/ae.c index 3d3569865..e1f9ceb1a 100644 --- a/src/ae.c +++ b/src/ae.c @@ -305,7 +305,7 @@ static int processTimeEvents(aeEventLoop *eventLoop) { } if (te->when <= now) { - int retval; + long long retval; id = te->id; te->refcount++; diff --git a/src/ae.h b/src/ae.h index 5f1e17f7d..0d097dbb1 100644 --- a/src/ae.h +++ b/src/ae.h @@ -43,7 +43,7 @@ struct aeEventLoop; /* Types and data structures */ typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask); -typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData); +typedef long long aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData); typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData); typedef void aeBeforeSleepProc(struct aeEventLoop *eventLoop); diff --git a/src/evict.c b/src/evict.c index 890a845d5..332638d05 100644 --- a/src/evict.c +++ b/src/evict.c @@ -434,7 +434,7 @@ int overMaxmemoryAfterAlloc(size_t moremem) { * eviction cycles until the "maxmemory" condition has resolved or there are no * more evictable items. */ static int isEvictionProcRunning = 0; -static int evictionTimeProc( +static long long evictionTimeProc( struct aeEventLoop *eventLoop, long long id, void *clientData) { UNUSED(eventLoop); UNUSED(id); diff --git a/src/module.c b/src/module.c index ced079f2f..f9681faeb 100644 --- a/src/module.c +++ b/src/module.c @@ -9149,7 +9149,7 @@ typedef struct RedisModuleTimer { /* This is the timer handler that is called by the main event loop. We schedule * this timer to be called when the nearest of our module timers will expire. */ -int moduleTimerHandler(struct aeEventLoop *eventLoop, long long id, void *clientData) { +static long long moduleTimerHandler(struct aeEventLoop *eventLoop, long long id, void *clientData) { UNUSED(eventLoop); UNUSED(id); UNUSED(clientData); diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 94151ba8a..64a24bb2d 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -177,8 +177,7 @@ static redisContext *getRedisContext(const char *ip, int port, static void freeRedisConfig(redisConfig *cfg); static int fetchClusterSlotsConfiguration(client c); static void updateClusterSlotsConfiguration(void); -int showThroughput(struct aeEventLoop *eventLoop, long long id, - void *clientData); +static long long showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData); /* Dict callbacks */ static uint64_t dictSdsHash(const void *key); @@ -1633,7 +1632,7 @@ tls_usage, exit(exit_status); } -int showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData) { +static long long showThroughput(struct aeEventLoop *eventLoop, long long id, void *clientData) { UNUSED(eventLoop); UNUSED(id); benchmarkThread *thread = (benchmarkThread *)clientData; diff --git a/src/server.c b/src/server.c index 1a7bf2700..6cfe8bb88 100644 --- a/src/server.c +++ b/src/server.c @@ -1270,7 +1270,7 @@ void cronUpdateMemoryStats(void) { * a macro is used: run_with_period(milliseconds) { .... } */ -int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { +static long long serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { int j; UNUSED(eventLoop); UNUSED(id);