1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

uucore: use Duration::saturating_mul in parse_time

Use `Duration::saturating_mul()` to avoid a panic due to overflow in
`uucore::parse_time::from_str()`. This change prevents panic on very
large arguments to timeout and sleep.
This commit is contained in:
Jeffrey Finkelstein 2022-03-17 19:03:26 -04:00
parent 8c36558871
commit 388cb6c83a
3 changed files with 99 additions and 1 deletions

View file

@ -1,3 +1,4 @@
// spell-checker:ignore dont
use crate::common::util::*;
use std::time::{Duration, Instant};
@ -115,3 +116,18 @@ fn test_sleep_sum_duration_many() {
fn test_sleep_wrong_time() {
new_ucmd!().args(&["0.1s", "abc"]).fails();
}
// TODO These tests would obviously block for a very long time. We
// only want to verify that there is no error here, so we could just
// figure out a way to terminate the child process after a short
// period of time.
// #[test]
#[allow(dead_code)]
fn test_dont_overflow() {
new_ucmd!()
.arg("9223372036854775808d")
.succeeds()
.no_stderr()
.no_stdout();
}