git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "darcy via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: darcy <acednes@gmail.com>, darcy <acednes@gmail.com>
Subject: [PATCH] fix: prevent date underflow when using positive timezone offset
Date: Mon, 27 May 2024 09:17:06 +0000	[thread overview]
Message-ID: <pull.1726.git.git.1716801427015.gitgitgadget@gmail.com> (raw)

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

             reply	other threads:[~2024-05-27  9:17 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  9:17 darcy via GitGitGadget [this message]
2024-05-28 14:05 ` [PATCH] fix: prevent date underflow when using positive timezone offset Patrick Steinhardt
2024-05-28 14:49   ` Phillip Wood
2024-05-28 17:06   ` Junio C Hamano
2024-06-02 23:06 ` [PATCH v2] date: detect underflow when parsing dates with " darcy via GitGitGadget
2024-06-03 11:13   ` Junio C Hamano
2024-06-03 11:44     ` darcy
2024-06-03 14:13       ` Phillip Wood
2024-06-04  8:48         ` darcy
2024-06-04  9:33           ` Jeff King
2024-06-05  6:52             ` darcy
2024-06-05 13:10           ` Phillip Wood
2024-06-05 17:27             ` Junio C Hamano
2024-06-06  4:56               ` darcy
2024-06-07  0:17   ` [PATCH v3] date: detect underflow/overflow when parsing dates with " darcy via GitGitGadget
2024-06-07 17:40     ` Junio C Hamano
2024-06-08 18:58       ` Junio C Hamano
2024-06-14  1:20         ` Junio C Hamano
2024-06-15 11:47           ` Karthik Nayak
2024-06-11 23:30       ` Junio C Hamano
2024-06-11 23:49         ` rsbecker
2024-06-11 23:52           ` Junio C Hamano
2024-06-25 23:12         ` [PATCH v4 0/2] Darcy's "date underflow fix" topic, final reroll Junio C Hamano
2024-06-25 23:12           ` [PATCH v4 1/2] t0006: simplify prerequisites Junio C Hamano
2024-06-25 23:30             ` Eric Sunshine
2024-06-26  0:04               ` Junio C Hamano
2024-06-25 23:12           ` [PATCH v4 2/2] date: detect underflow/overflow when parsing dates with timezone offset Junio C Hamano
2024-06-26 15:21           ` [PATCH v4 0/2] Darcy's "date underflow fix" topic, final reroll Phillip Wood
2024-06-26 18:32             ` Junio C Hamano
2024-06-12  9:07       ` [PATCH v3] date: detect underflow/overflow when parsing dates with timezone offset Phillip Wood
2024-06-12  9:49     ` Karthik Nayak
2024-06-13 13:31       ` Phillip Wood
2024-06-13 16:16         ` Junio C Hamano
2024-06-14 20:09           ` Karthik Nayak
2024-06-14 21:02             ` Junio C Hamano
2024-06-15 11:49               ` Karthik Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1726.git.git.1716801427015.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=acednes@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).