Skip to content

Commit 10220a8

Browse files
committed
Reject %y in strftime for year < 1900 on Windows
1 parent 432ee0a commit 10220a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/vm/src/stdlib/time.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,22 @@ mod decl {
631631
if !(1..=9999).contains(&year) {
632632
return Err(vm.new_value_error("strftime() requires year in [1; 9999]".to_owned()));
633633
}
634+
// %y requires year >= 1900 on Windows
635+
if tm.tm_year < 0 {
636+
let fmt = format.as_str();
637+
let mut chars = fmt.chars();
638+
while let Some(ch) = chars.next() {
639+
if ch == '%' {
640+
if let Some(next) = chars.next() {
641+
if next == 'y' {
642+
return Err(vm.new_value_error(
643+
"format %y requires year >= 1900 on Windows".to_owned(),
644+
));
645+
}
646+
}
647+
}
648+
}
649+
}
634650
}
635651

636652
#[cfg(unix)]

0 commit comments

Comments
 (0)