From 1cd749cc0722533bd1849f491ec9ab19e17232e1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 28 Sep 2009 23:40:09 -0700 Subject: [PATCH] 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 --- fast-import.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fast-import.c b/fast-import.c index 7ef9865aa..6faaaacb6 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1744,10 +1744,12 @@ static int validate_raw_date(const char *src, char *result, int maxlen) { const char *orig_src = src; char *endp; + unsigned long num; errno = 0; - strtoul(src, &endp, 10); + num = strtoul(src, &endp, 10); + /* NEEDSWORK: perhaps check for reasonable values? */ if (errno || endp == src || *endp != ' ') return -1; @@ -1755,8 +1757,9 @@ static int validate_raw_date(const char *src, char *result, int maxlen) if (*src != '-' && *src != '+') return -1; - strtoul(src + 1, &endp, 10); - if (errno || endp == src || *endp || (endp - orig_src) >= maxlen) + num = strtoul(src + 1, &endp, 10); + if (errno || endp == src + 1 || *endp || (endp - orig_src) >= maxlen || + 1400 < num) return -1; strcpy(result, orig_src); -- 2.30.2