summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOzan Tezcan <ozantezcan@gmail.com>2021-11-11 14:51:33 +0300
committerOran Agra <oran@redislabs.com>2022-04-27 16:31:52 +0300
commit49c1c96fc13f7e461e93c148bed1410556b52ff8 (patch)
tree6a4b57934c5addfcc6dfa7eacc9742c33c9dbe33
parentd92f2f5ad616b2ddb22dda4359917be7c66b0a17 (diff)
downloadredis-49c1c96fc13f7e461e93c148bed1410556b52ff8.tar.gz
Fix overflow check in expireGenericCommand
Partial cherry pick from #9601 in order for the tests in #9601 to pass (cherry picked from commit b91d8b289bb64965c5eaa445809f9f49293e99c0)
-rw-r--r--src/expire.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/expire.c b/src/expire.c
index f23a79b82..5d2f2c9b7 100644
--- a/src/expire.c
+++ b/src/expire.c
@@ -493,15 +493,23 @@ void expireGenericCommand(client *c, long long basetime, int unit) {
if (getLongLongFromObjectOrReply(c, param, &when, NULL) != C_OK)
return;
- int negative_when = when < 0;
- if (unit == UNIT_SECONDS) when *= 1000;
- when += basetime;
- if (((when < 0) && !negative_when) || ((when-basetime > 0) && negative_when)) {
- /* EXPIRE allows negative numbers, but we can at least detect an
- * overflow by either unit conversion or basetime addition. */
+
+ /* EXPIRE allows negative numbers, but we can at least detect an
+ * overflow by either unit conversion or basetime addition. */
+ if (unit == UNIT_SECONDS) {
+ if (when > LLONG_MAX / 1000 || when < LLONG_MIN / 1000) {
+ addReplyErrorFormat(c, "invalid expire time in %s", c->cmd->name);
+ return;
+ }
+ when *= 1000;
+ }
+
+ if (when > LLONG_MAX - basetime) {
addReplyErrorFormat(c, "invalid expire time in %s", c->cmd->name);
return;
}
+ when += basetime;
+
/* No key, return zero. */
if (lookupKeyWrite(c->db,key) == NULL) {
addReply(c,shared.czero);