git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] fast-import.c::validate_raw_date(): really validate the value

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 29, 2009, 06:40 UTC
Message-ID
<1254206409-13256-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1254206409-13256-1-git-send-email-gitster@pobox.com>

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>
---
 fast-import.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 7ef9865..6faaaac 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);
-- 
1.6.3
Previous: Junio C HamanoNext: Shawn O. Pearce
Message 2 of 3 in “builtin-mailinfo.c: check error status from rewind and ftruncate”
  1. 1/2 builtin-mailinfo.c: check error status from rewind and ftruncateJunio C Hamano, Sep 29, 2009
  2. 2/2 fast-import.c::validate_raw_date(): really validate the valueJunio C Hamano, Sep 29, 2009
  3. Shawn O. PearceSep 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.