Describe the bug
In expireGenericCommand, if input time for expire causes to overflow on "when" variable , so we have a undefined behavior.
To reproduce
This is a long time but it may be requested
when = LLONG_MAX - 1000;
Expected behavior
expected ttl set to LLONG_MAX - 1000; but an overflow occurs.
Additional information
my solution is
if (unit == UNIT_SECONDS)
{
if (when >= (LLONG_MAX / 1000) - basetime)
{
persistcommand();
return;
}
when *=1000;
}
if (when >= LLONG_MAX - basetime)
{
persistcommand();
return;
}
when += basetime;
Comment From: itamarhaber
Thanks for the report @mmhatami - I can verify that an overflow occurs when, for example, calling SET foo bar EX 9223372036854774807. This leads to the key being deleted, naturally.
Comment From: filipecosta90
@itamarhaber @mmhatami I believe this PR should fix it correct? https://github.com/redis/redis/pull/6801 PS: this issue is a duplicate of https://github.com/redis/redis/issues/6800
Comment From: oranagra
why would someone want to have the key expire in 292471208677 years?
Comment From: itamarhaber
Thanks @filipecosta90 - totally forgot about that one :)
As for why would someone want to do that, I guess no one will really do it (and anyway, 2038 is the end of everything) but the edge case of the overflow is still there for static analyzers and hoomans alike.
If everyone's in agreement, I think this can be closed as a duplicate.
Comment From: oranagra
they're not strictly duplicate since each of them is about the same bug in a different command. i've set the PR to close both when merged, assuming @filipecosta90 will update his PR (commented there).
Comment From: oranagra
fixed by #8287