Skip to content

Commit 256817a

Browse files
Cap duration at time_t::MAX seconds.
1 parent 533a4e7 commit 256817a

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/uu/timeout/src/timeout.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,22 @@ impl Config {
8383
},
8484
};
8585

86-
let duration = match parse_time::from_str(
87-
options.get_one::<String>(options::DURATION).unwrap(),
88-
true,
89-
) {
90-
Ok(d) => d,
91-
Err(err) => {
92-
// If parsing fails due to overflow, use maximum valid duration
93-
// This handles cases like "9223372036854775808d" (i64::MAX days)
94-
let err_str = err.to_string();
95-
if err_str.contains("overflow") || err_str.contains("too large") {
96-
// Cap at time_t::MAX seconds (maximum valid timeout)
97-
Duration::from_secs(libc::time_t::MAX as u64)
98-
} else {
99-
return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err));
86+
let duration =
87+
match parse_time::from_str(options.get_one::<String>(options::DURATION).unwrap(), true)
88+
{
89+
Ok(d) => d,
90+
Err(err) => {
91+
// If parsing fails due to overflow, use maximum valid duration
92+
// This handles cases like "9223372036854775808d" (i64::MAX days)
93+
let err_str = err.clone();
94+
if err_str.contains("overflow") || err_str.contains("too large") {
95+
// Cap at time_t::MAX seconds (maximum valid timeout)
96+
Duration::from_secs(libc::time_t::MAX as u64)
97+
} else {
98+
return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err));
99+
}
100100
}
101-
}
102-
};
101+
};
103102

104103
let preserve_status: bool = options.get_flag(options::PRESERVE_STATUS);
105104
let foreground = options.get_flag(options::FOREGROUND);

0 commit comments

Comments
 (0)