Skip to content

Commit

Permalink
fast-import.c: stricter strtoul check, silence compiler warning
Browse files Browse the repository at this point in the history
Store the return value of strtoul() in order to avoid compiler
warnings on Ubuntu 8.10.

Also check errno after each call, which is the only way to notice
an overflow without making ULONG_MAX an illegal date.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Dec 21, 2008
1 parent 8f14825 commit c55fae4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,18 +1748,21 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
{
const char *orig_src = src;
char *endp, sign;
unsigned long date;

strtoul(src, &endp, 10);
if (endp == src || *endp != ' ')
errno = 0;

date = strtoul(src, &endp, 10);
if (errno || endp == src || *endp != ' ')
return -1;

src = endp + 1;
if (*src != '-' && *src != '+')
return -1;
sign = *src;

strtoul(src + 1, &endp, 10);
if (endp == src || *endp || (endp - orig_src) >= maxlen)
date = strtoul(src + 1, &endp, 10);
if (errno || endp == src || *endp || (endp - orig_src) >= maxlen)
return -1;

strcpy(result, orig_src);
Expand Down

0 comments on commit c55fae4

Please sign in to comment.