diff options
author | Thomas O'Donnell <andytom@users.noreply.github.com> | 2021-02-13 14:35:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-13 14:35:15 +0100 |
commit | 118f18785aa6f2c61878b26d6a625204a05a339b (patch) | |
tree | fbb670100235c1d87a559f8720ab0e77aa8cf381 /src | |
parent | 47a769cdf85d6f42250fe179e482ca40647bb2d8 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/utils.rs b/src/utils.rs index 8d73a3f42..7dfe1406e 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<C match process.with_output_timeout(time_limit).terminating().wait() { Ok(Some(output)) => { - 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 {:?}", |