From 118f18785aa6f2c61878b26d6a625204a05a339b Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Sat, 13 Feb 2021 14:35:15 +0100 Subject: [PATCH] fix(utils): Sefely unwrap the command output (#2305) Safely unwrap the output of the commands executed by `utils::exec_cmd`, this should avoid panics when the output of the command cannot be decoded. --- src/utils.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 8d73a3f4..7dfe1406 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -287,8 +287,20 @@ fn internal_exec_cmd(cmd: &str, args: &[&str], time_limit: Duration) -> Option { - let stdout_string = String::from_utf8(output.stdout).unwrap(); - let stderr_string = String::from_utf8(output.stderr).unwrap(); + let stdout_string = match String::from_utf8(output.stdout) { + Ok(stdout) => stdout, + Err(error) => { + log::warn!("Unable to decode stdout: {:?}", error); + return None; + } + }; + let stderr_string = match String::from_utf8(output.stderr) { + Ok(stderr) => stderr, + Err(error) => { + log::warn!("Unable to decode stderr: {:?}", error); + return None; + } + }; log::trace!( "stdout: {:?}, stderr: {:?}, exit code: \"{:?}\", took {:?}",