Commit cfb1ac1
committed
date: avoid overflow in approxidate relative-time multiplication
approxidate_alpha() multiplies a time unit length (e.g., 604800
for weeks) by a user-supplied number to compute a time offset in
seconds. Both operands are int, and the product is passed to
update_tm() as time_t. For inputs like "99999 weeks ago", the
int multiplication overflows (604800 * 99999 = ~60 billion,
far beyond INT_MAX), producing a wrapped value that results in
a wrong date.
Widen the operands to time_t before multiplying and use
mult_overflows() to detect when even the wider product would
overflow. On overflow, clamp to the maximum value of time_t
(using is_unsigned_type to select the appropriate maximum).
The clamped value causes update_tm to produce a date at the
epoch boundary, which is a reasonable degraded behavior for
an absurdly large relative offset.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent 691459d commit cfb1ac1
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1272 | 1272 | | |
1273 | 1273 | | |
1274 | 1274 | | |
1275 | | - | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
1276 | 1282 | | |
1277 | 1283 | | |
1278 | 1284 | | |
| |||
0 commit comments