Skip to content

Commit 1cd749c

Browse files
committed
fast-import.c::validate_raw_date(): really validate the value
When reading the "raw format" timestamp from the input stream, make sure that the timezone offset is a reasonable value by imitating 7122f82 (date.c: improve guess between timezone offset and year., 2006-06-08). We _might_ want to also check if the timestamp itself is reasonable, but that is left for a separate commit. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04ce83e commit 1cd749c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fast-import.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,19 +1744,22 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
17441744
{
17451745
const char *orig_src = src;
17461746
char *endp;
1747+
unsigned long num;
17471748

17481749
errno = 0;
17491750

1750-
strtoul(src, &endp, 10);
1751+
num = strtoul(src, &endp, 10);
1752+
/* NEEDSWORK: perhaps check for reasonable values? */
17511753
if (errno || endp == src || *endp != ' ')
17521754
return -1;
17531755

17541756
src = endp + 1;
17551757
if (*src != '-' && *src != '+')
17561758
return -1;
17571759

1758-
strtoul(src + 1, &endp, 10);
1759-
if (errno || endp == src || *endp || (endp - orig_src) >= maxlen)
1760+
num = strtoul(src + 1, &endp, 10);
1761+
if (errno || endp == src + 1 || *endp || (endp - orig_src) >= maxlen ||
1762+
1400 < num)
17601763
return -1;
17611764

17621765
strcpy(result, orig_src);

0 commit comments

Comments
 (0)