aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-01-21 07:58:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-01-21 07:58:18 +0100
commit3b394781b5b9301fc489d9bfff6fbefb4db190f3 (patch)
tree521043a42ff52b3e618f4251c99dd85f656c22b1
parent2de232da53da6a79880defc5693242383af58764 (diff)
downloadbusybox-w32-3b394781b5b9301fc489d9bfff6fbefb4db190f3.tar.gz
busybox-w32-3b394781b5b9301fc489d9bfff6fbefb4db190f3.tar.bz2
busybox-w32-3b394781b5b9301fc489d9bfff6fbefb4db190f3.zip
libbb: fix parsing of "10101010" date/time form
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/time.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libbb/time.c b/libbb/time.c
index ea2f72e3b..aa19a47d4 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -68,15 +68,23 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
68 /* else end != NUL and we error out */ 68 /* else end != NUL and we error out */
69 } 69 }
70 } else 70 } else
71 /* yyyy-mm-dd HH */ 71 if (strchr(date_str, '-')
72 if (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year, 72 /* Why strchr('-') check?
73 * sscanf below will trash ptm->tm_year, this breaks
74 * if parse_str is "10101010" (iow, "MMddhhmm" form)
75 * because we destroy year. Do these sscanf
76 * only if we saw a dash in parse_str.
77 */
78 /* yyyy-mm-dd HH */
79 && (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year,
73 &ptm->tm_mon, &ptm->tm_mday, 80 &ptm->tm_mon, &ptm->tm_mday,
74 &ptm->tm_hour, 81 &ptm->tm_hour,
75 &end) >= 4 82 &end) >= 4
76 /* yyyy-mm-dd */ 83 /* yyyy-mm-dd */
77 || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year, 84 || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year,
78 &ptm->tm_mon, &ptm->tm_mday, 85 &ptm->tm_mon, &ptm->tm_mday,
79 &end) >= 3 86 &end) >= 3
87 )
80 ) { 88 ) {
81 ptm->tm_year -= 1900; /* Adjust years */ 89 ptm->tm_year -= 1900; /* Adjust years */
82 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 90 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */