SHA256
1
0
forked from pool/patch
patch/fix-timestamp-parsing.diff

59 lines
2.0 KiB
Diff

* str2time() will happily parse "\n" and similar; the result will be
undistinguishable from a valid timestamp. Avoid this by skipping
whitespace before and checking if anything remains first.
* Always parse timestamps in patch headers relative to the local timezone
or UTC so that pch_timestamp() will always contain reasonable values
if a timestamp is present: we may need the timestamps later.
* Change the bizarre logic which checks whether a timestamp is close to
the epoch by checking for exactly that. The result is the same, and we
won't have to parse the timestamp again.
---
util.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
Index: b/util.c
===================================================================
--- a/util.c
+++ b/util.c
@@ -996,25 +996,23 @@ fetchname (char *at, int strip_leading,
if (*u != '\t' && strchr (u + 1, '\t'))
continue;
- if (set_time | set_utc)
- stamp = str2time (&u, initial_time,
- set_utc ? 0L : TM_LOCAL_ZONE);
- else
- {
+ while (ISSPACE((unsigned char) *u))
+ u++;
+ if (*u) {
+ stamp = str2time (&u, initial_time,
+ set_utc ? 0L : TM_LOCAL_ZONE);
+
/* The head says the file is nonexistent if the timestamp
is the epoch; but the listed time is local time, not UTC,
and POSIX.1 allows local time offset anywhere in the range
- -25:00 < offset < +26:00. Match any time in that
- range by assuming local time is -25:00 and then matching
- any ``local'' time T in the range 0 < T < 25+26 hours. */
- stamp = str2time (&u, initial_time, -25L * 60 * 60);
- if (0 < stamp && stamp < (25 + 26) * 60L * 60)
+ -25:00 < offset < +26:00. Match any time in that range. */
+ if (!(set_time || set_utc)
+ && 25 * 60L * 60 < stamp && stamp < 26 * 60L * 60)
stamp = 0;
- }
-
- if (*u && ! ISSPACE ((unsigned char) *u))
- stamp = (time_t) -1;
+ if (*u && ! ISSPACE ((unsigned char) *u))
+ stamp = (time_t) -1;
+ }
*t = '\0';
break;
}