From 169be0426c5a4b4eedc04ad94a165c002101e5b2 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Wed, 17 Mar 2021 14:45:38 +0100 Subject: [PATCH] Fixes for systems with 64-bit time (#8662) Some operating systems (e.g., NetBSD and OpenBSD) have switched to using a 64-bit integer for time_t on all platforms. This results in currently harmless compiler warnings due to potential truncation. These changes fix these minor portability concerns. * Fix format string for systems with 64 bit time * use llabs to avoid truncation with 64 bit time --- src/debug.c | 2 +- src/networking.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/debug.c b/src/debug.c index e7fec293a..2e9d4d1e4 100644 --- a/src/debug.c +++ b/src/debug.c @@ -473,7 +473,7 @@ NULL } else if (!strcasecmp(c->argv[1]->ptr,"segfault")) { *((char*)-1) = 'x'; } else if (!strcasecmp(c->argv[1]->ptr,"panic")) { - serverPanic("DEBUG PANIC called at Unix time %ld", time(NULL)); + serverPanic("DEBUG PANIC called at Unix time %lld", (long long)time(NULL)); } else if (!strcasecmp(c->argv[1]->ptr,"restart") || !strcasecmp(c->argv[1]->ptr,"crash-and-recover")) { diff --git a/src/networking.c b/src/networking.c index 7d184bae7..7484a8940 100644 --- a/src/networking.c +++ b/src/networking.c @@ -3008,7 +3008,7 @@ void securityWarningCommand(client *c) { static time_t logged_time; time_t now = time(NULL); - if (labs(now-logged_time) > 60) { + if (llabs(now-logged_time) > 60) { serverLog(LL_WARNING,"Possible SECURITY ATTACK detected. It looks like somebody is sending POST or Host: commands to Redis. This is likely due to an attacker attempting to use Cross Protocol Scripting to compromise your Redis instance. Connection aborted."); logged_time = now; }