aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-09-23 20:27:32 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-09-23 20:27:32 +0200
commit76832ff5c4f107f8a8165fcafc9b05a888cdb964 (patch)
tree4e224d18d3691d5327400abfea1f50918c3474b4
parent6608879d34f9635572415e864b4fcbc497c74bcf (diff)
downloadbusybox-w32-76832ff5c4f107f8a8165fcafc9b05a888cdb964.tar.gz
busybox-w32-76832ff5c4f107f8a8165fcafc9b05a888cdb964.tar.bz2
busybox-w32-76832ff5c4f107f8a8165fcafc9b05a888cdb964.zip
date: do not allow "month #20" and such, closes 11356
function old new delta parse_datestr 906 961 +55 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/time.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libbb/time.c b/libbb/time.c
index 82e6cb172..f9b8da0b3 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -184,6 +184,7 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
184 ptm->tm_year -= 1900; /* Adjust years */ 184 ptm->tm_year -= 1900; /* Adjust years */
185 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 185 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
186 } else { 186 } else {
187 err:
187 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 188 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
188 } 189 }
189 ptm->tm_sec = 0; /* assume zero if [.SS] is not given */ 190 ptm->tm_sec = 0; /* assume zero if [.SS] is not given */
@@ -194,6 +195,19 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
194 end = '\0'; 195 end = '\0';
195 /* else end != NUL and we error out */ 196 /* else end != NUL and we error out */
196 } 197 }
198 /* Users were confused by "date -s 20180923"
199 * working (not in the way they were expecting).
200 * It was interpreted as MMDDhhmm, and not bothered by
201 * "month #20" in the least. Prevent such cases:
202 */
203 if (ptm->tm_sec > 60 /* allow "23:60" leap second */
204 || ptm->tm_min > 59
205 || ptm->tm_hour > 23
206 || ptm->tm_mday > 31
207 || ptm->tm_mon > 11 /* month# is 0..11, not 1..12 */
208 ) {
209 goto err;
210 }
197 } 211 }
198 if (end != '\0') { 212 if (end != '\0') {
199 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 213 bb_error_msg_and_die(bb_msg_invalid_date, date_str);