1
0
mirror of https://github.com/kata-containers/kata-containers.git synced 2025-05-12 02:15:28 +00:00

runtime-rs: fix panic when hypervisor mismatches with configuration

If a wrong configuration.toml file is used by accidentally, runtime-rs
binary could run into panic because of unwrap().

This fixes the panic by returning errors instead of unwrap().

fixes: 

Signed-off-by: Liu Bo <liub.liubo@gmail.com>
This commit is contained in:
Liu Bo 2023-12-04 22:24:45 -08:00
parent 9d38f01c2f
commit bf97051f11

View File

@ -479,8 +479,18 @@ impl Annotation {
let u32_err = io::Error::new(io::ErrorKind::InvalidData, "parse u32 error".to_string());
let u64_err = io::Error::new(io::ErrorKind::InvalidData, "parse u64 error".to_string());
let i32_err = io::Error::new(io::ErrorKind::InvalidData, "parse i32 error".to_string());
let hv = config.hypervisor.get_mut(hypervisor_name).unwrap();
let ag = config.agent.get_mut(agent_name).unwrap();
let hv = config.hypervisor.get_mut(hypervisor_name).ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Invalid hypervisor name {}", hypervisor_name),
)
})?;
let ag = config.agent.get_mut(agent_name).ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Invalid agent name {}", agent_name),
)
})?;
for (key, value) in &self.annotations {
if hv.security_info.is_annotation_enabled(key) {
match key.as_str() {