From 2e5c0b5d863cfb1d2746022441edeaefe301df97 Mon Sep 17 00:00:00 2001 From: Nick Rirush Date: Mon, 5 Nov 2018 11:55:13 +0800 Subject: [PATCH] Remove all unwraps, so code won't panic in some cases --- src/main.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 54d648e..5b435c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,11 +64,22 @@ pub extern "win64" fn uefi_start(_image: uefi::Handle, table: SystemTable) match result { Ok(file) => { let mut file = file.unwrap(); - - // TODO: Don't panic here - let size = file.read(&mut buf).unwrap().unwrap(); - // TODO: Don't panic here too - config = from_slice(&buf[..size]).unwrap(); + let result = file.read(&mut buf); + match result { + Ok(size) => { + let size = size.unwrap(); + if let Ok(c) = from_slice::(&buf[..size]) { + config = c; + } else { + error!("Failed to parse configuration file"); + info!("Using default configuration instead"); + } + } + Err(_) => { + error!("Failed to read configuration, file is too large"); + info!("Using default configuration instead"); + } + } } Err(_) => { warn!("\\EFI\\COONBOOT\\boot.json not found, using default configuration");