@matheusbsbs / matheus-bagliano / commits / 1cd749cc07
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Sep 28, 2009 at 23:40 UTC 1cd749cc0722533bd1849f491ec9ab19e17232e1
1 file changed +6 -3
fast-import.c
+6 -3
@@ -1744,10 +1744,12 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
1744 {
1745 const char *orig_src = src;
1746 char *endp;
1747 + unsigned long num;
1748
1749 errno = 0;
1750
1750 - strtoul(src, &endp, 10);
1751 + num = strtoul(src, &endp, 10);
1752 + /* NEEDSWORK: perhaps check for reasonable values? */
1753 if (errno || endp == src || *endp != ' ')
1754 return -1;
1755
@@ -1755,8 +1757,9 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
1757 if (*src != '-' && *src != '+')
1758 return -1;
1759
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)
1763 return -1;
1764
1765 strcpy(result, orig_src);