Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 3f419d4

Browse files
peffgitster
authored andcommitted
show_ident_date: fix tz range check
Commit 1dca155 (log: handle integer overflow in timestamps, 2014-02-24) tried to catch integer overflow coming from strtol() on the timezone field by comparing against LONG_MIN/LONG_MAX. However, the intermediate "tz" variable is an "int", which means it can never be LONG_MAX on LP64 systems; we would truncate the output from strtol before the comparison. Clang's -Wtautological-constant-out-of-range-compare notices this and rightly complains. Let's instead store the result of strtol in a long, and then compare it against INT_MIN/INT_MAX. This will catch overflow from strtol, and also overflow when we pass the result as an int to show_date. Reported-by: Eric Sunshine <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b15846 commit 3f419d4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pretty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static const char *show_ident_date(const struct ident_split *ident,
397397
enum date_mode mode)
398398
{
399399
unsigned long date = 0;
400-
int tz = 0;
400+
long tz = 0;
401401

402402
if (ident->date_begin && ident->date_end)
403403
date = strtoul(ident->date_begin, NULL, 10);
@@ -406,7 +406,7 @@ static const char *show_ident_date(const struct ident_split *ident,
406406
else {
407407
if (ident->tz_begin && ident->tz_end)
408408
tz = strtol(ident->tz_begin, NULL, 10);
409-
if (tz == LONG_MAX || tz == LONG_MIN)
409+
if (tz >= INT_MAX || tz <= INT_MIN)
410410
tz = 0;
411411
}
412412
return show_date(date, tz, mode);

0 commit comments

Comments
 (0)