mirror of https://github.com/redis/redis.git
Fix overflow check in expireGenericCommand
Partial cherry pick from #9601 in order for the tests in #9601 to pass
(cherry picked from commit b91d8b289b)
This commit is contained in:
parent
d92f2f5ad6
commit
49c1c96fc1
20
src/expire.c
20
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue