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

[PATCH] fix: prevent date underflow when using positive timezone offset

From
darcy via GitGitGadget <gitgitgadget@gmail.com>
Date
May 27, 2024, 09:17 UTC
Message-ID
<pull.1726.git.git.1716801427015.gitgitgadget@gmail.com>
From: darcy <acednes@gmail.com>

Overriding the date of a commit to be `1970-01-01` with a large enough timezone for the equivalent GMT time to before 1970 is no longer accepted.

Example: `GIT_COMMITTER_DATE='1970-01-01T00:00:00+10' git commit` would
previously be accepted, only to unexpectedly fail in other parts of the
code, such as `git push`. The timestamp is now checked against postitive
timezone values.
Signed-off-by: darcy <acednes@gmail.com>
---
    fix: prevent date underflow when using positive timezone offset
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1726%2Fdxrcy%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1726/dxrcy/master-v1
Pull-Request: https://github.com/git/git/pull/1726
 date.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/date.c b/date.c
index 7365a4ad24f..8388629f267 100644
--- a/date.c
+++ b/date.c
@@ -908,7 +908,7 @@ int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset)
 			match = match_alpha(date, &tm, offset);
 		else if (isdigit(c))
 			match = match_digit(date, &tm, offset, &tm_gmt);
-		else if ((c == '-' || c == '+') && isdigit(date[1]))
+		else if ((c == '-' || c == '+') && isdigit(date[1]) && tm.tm_hour != -1)
 			match = match_tz(date, offset);
 
 		if (!match) {
@@ -937,8 +937,13 @@ int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset)
 		}
 	}
 
-	if (!tm_gmt)
+	if (!tm_gmt) {
+		if (*offset > 0 && *offset * 60 > *timestamp) {
+			return -1;
+		}
 		*timestamp -= *offset * 60;
+	}
+
 	return 0; /* success */
 }
 

base-commit: b9cfe4845cb2562584837bc0101c0ab76490a239
-- 
gitgitgadget
Next: Patrick Steinhardt
Message 1 of 29 in “fix: prevent date underflow when using positive timezone offset”
  1. fix: prevent date underflow when using positive timezone offsetdarcy via GitGitGadget, May 27, 2024
  2. Patrick SteinhardtMay 28, 2024
  3. Phillip WoodMay 28, 2024
  4. Junio C HamanoMay 28, 2024
  5. date: detect underflow when parsing dates with positive timezone offsetdarcy via GitGitGadget, Jun 2, 2024
  6. Junio C HamanoJun 3, 2024
  7. darcyJun 3, 2024
  8. Phillip WoodJun 3, 2024
  9. darcyJun 4, 2024
  10. Jeff KingJun 4, 2024
  11. darcyJun 5, 2024
  12. Phillip WoodJun 5, 2024
  13. Junio C HamanoJun 5, 2024
  14. darcyJun 6, 2024
  15. date: detect underflow/overflow when parsing dates with timezone offsetdarcy via GitGitGadget, Jun 7, 2024
  16. Junio C HamanoJun 7, 2024
  17. Junio C HamanoJun 8, 2024
  18. Junio C HamanoJun 14, 2024
  19. Karthik NayakJun 15, 2024
  20. Junio C HamanoJun 11, 2024
  21. rsbecker@nexbridge.comJun 11, 2024
  22. Junio C HamanoJun 11, 2024
  23. Phillip WoodJun 12, 2024
  24. Karthik NayakJun 12, 2024
  25. Phillip WoodJun 13, 2024
  26. Junio C HamanoJun 13, 2024
  27. Karthik NayakJun 14, 2024
  28. Junio C HamanoJun 14, 2024
  29. Karthik NayakJun 15, 2024

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.