mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 13:50:16 +00:00
fix(menu): check for timeout duration overflow
This commit is contained in:
11
src/menu.rs
11
src/menu.rs
@@ -40,8 +40,17 @@ fn read(input: &mut Input, timeout: &Duration) -> Result<MenuOperation> {
|
||||
uefi::boot::create_event_ex(EventType::TIMER, Tpl::CALLBACK, None, None, None)
|
||||
.context("unable to create timer event")?
|
||||
};
|
||||
|
||||
// The timeout is in increments of 100 nanoseconds.
|
||||
let trigger = TimerTrigger::Relative(timeout.as_nanos() as u64 / 100);
|
||||
let timeout_hundred_nanos = timeout.as_nanos() / 100;
|
||||
|
||||
// Check if the timeout is too large to fit into an u64.
|
||||
if timeout_hundred_nanos > u64::MAX as u128 {
|
||||
bail!("timeout duration overflow");
|
||||
}
|
||||
|
||||
// Set a timer to trigger after the specified duration.
|
||||
let trigger = TimerTrigger::Relative(timeout_hundred_nanos as u64);
|
||||
uefi::boot::set_timer(&timer_event, trigger).context("unable to set timeout timer")?;
|
||||
|
||||
let mut events = vec![timer_event, key_event];
|
||||
|
||||
Reference in New Issue
Block a user