summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2019-09-24 07:32:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-09-28 04:36:04 (GMT)
commit2e09c01232b1e1f5f383e62865b6049ff76270b3 (patch)
tree6f5b57576597e432ef4f501e7048ef435d5b6a49 /git-compat-util.h
parent5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff)
downloadgit-2e09c01232b1e1f5f383e62865b6049ff76270b3.zip
git-2e09c01232b1e1f5f383e62865b6049ff76270b3.tar.gz
git-2e09c01232b1e1f5f383e62865b6049ff76270b3.tar.bz2
name-rev: avoid cutoff timestamp underflow
When 'git name-rev' is invoked with commit-ish parameters, it tries to save some work, and doesn't visit commits older than the committer date of the oldest given commit minus a one day worth of slop. Since our 'timestamp_t' is an unsigned type, this leads to a timestamp underflow when the committer date of the oldest given commit is within a day of the UNIX epoch. As a result the cutoff timestamp ends up far-far in the future, and 'git name-rev' doesn't visit any commits, and names each given commit as 'undefined'. Check whether subtracting the slop from the oldest committer date would lead to an underflow, and use no cutoff in that case. We don't have a TIME_MIN constant, dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) didn't add one, so do it now. Note that the type of the cutoff timestamp variable used to be signed before 5589e87fd8 (name-rev: change a "long" variable to timestamp_t, 2017-05-20). The behavior was still the same even back then, but the underflow didn't happen when substracting the slop from the oldest committer date, but when comparing the signed cutoff timestamp with unsigned committer dates in name_rev(). IOW, this underflow bug is as old as 'git name-rev' itself. Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 83be89d..2e25356 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -344,6 +344,7 @@ typedef uintmax_t timestamp_t;
#define PRItime PRIuMAX
#define parse_timestamp strtoumax
#define TIME_MAX UINTMAX_MAX
+#define TIME_MIN 0
#ifndef PATH_SEP
#define PATH_SEP ':'