[PATCH 1/2] fast-import: be strict about formatting of raw dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



git proper never zero- or space-pads its dates and its time zones are
always 4 digits long.  Require fast-import front-ends to behave
likewise to avoid generating puzzling objects.

Since this makes the input format more strict, some front-ends may not
be happy.  But they were warned:

   This is the Git native format and is <time> SP <offutc>. It is also
   fast-import’s default format, if --date-format was not specified.

   Unlike the rfc2822 format, this format is very strict. Any variation
   in formatting will cause fast-import to reject the value.

Aside from ensuring the format is predictable so tools like git can
handle it, making the date format this strict ensures that there is
only one valid representation for a given date and time zone, which
would be useful for round-trip conversion of objects to and from other
formats (for storage by other version control systems, for example).

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
Is -0000 the same time zone as +0000?  I wasn’t sure so I erred on the
side of not worrying about it.

 fast-import.c          |    9 +++++++--
 t/t9300-fast-import.sh |   30 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 74f08bd..1701cf1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1906,6 +1906,8 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
 
 	errno = 0;
 
+	if ((*src == '0' && isdigit(src[1])) || !isdigit(*src))
+		return -1;
 	num = strtoul(src, &endp, 10);
 	/* NEEDSWORK: perhaps check for reasonable values? */
 	if (errno || endp == src || *endp != ' ')
@@ -1915,8 +1917,11 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
 	if (*src != '-' && *src != '+')
 		return -1;
 
-	num = strtoul(src + 1, &endp, 10);
-	if (errno || endp == src + 1 || *endp || (endp - orig_src) >= maxlen ||
+	src++;
+	if (*src != '0' && *src != '1')
+		return -1;
+	num = strtoul(src, &endp, 10);
+	if (errno || endp != src + 4 || *endp || (endp - orig_src) >= maxlen ||
 	    1400 < num)
 		return -1;
 
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 131f032..ed653a7 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -348,6 +348,36 @@ test_expect_success \
 
 cat >input <<INPUT_END
 commit refs/heads/branch
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170783301 -  0500
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 117078330 -0500
+data <<COMMIT
+Malformed time zone
+COMMIT
+
+from refs/heads/branch^0
+
+INPUT_END
+test_expect_success 'E: blanks in raw time zone' '
+    test_must_fail git fast-import --date-format=raw <input
+'
+
+cat >input <<INPUT_END
+commit refs/heads/branch
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 01170783301 -0500
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 117078330 -0500
+data <<COMMIT
+Malformed date
+COMMIT
+
+from refs/heads/branch^0
+
+INPUT_END
+test_expect_success 'E: leading zero in raw date' '
+    test_must_fail git fast-import --date-format=raw <input
+'
+
+cat >input <<INPUT_END
+commit refs/heads/branch
 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
 data <<COMMIT
-- 
1.7.1.rc1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]