diff --git a/src/backends/qemu/mod.rs b/src/backends/qemu/mod.rs index c6892c2..0a3cd6a 100644 --- a/src/backends/qemu/mod.rs +++ b/src/backends/qemu/mod.rs @@ -31,7 +31,7 @@ use serde::{Deserialize, Serialize}; use crate::{ backends::{Backend, BackendClientError, BackendRegistration}, - config::{ConfigError, load_config}, + config::ConfigError, instance::{Instance, InstanceClient}, util::Path, }; @@ -82,12 +82,12 @@ impl QemuConfig { /// Read `/qemu.json` if present, otherwise return the /// built-in defaults. pub fn from_dir(dir: &Path) -> Result { - let path = Path::new(&dir.join("qemu.json")); - if path.exists() { - load_config(path) - } else { - Ok(Self::default()) + let path = dir.join("qemu.json"); + if !path.exists() { + return Ok(Self::default()); } + let data = std::fs::read_to_string(&path)?; + Ok(serde_json::from_str(&data)?) } } diff --git a/src/engines/threshold.rs b/src/engines/threshold.rs index 01387c0..ef3f497 100644 --- a/src/engines/threshold.rs +++ b/src/engines/threshold.rs @@ -211,10 +211,10 @@ impl ThresholdEngine { /// Load `threshold.json`, falling back to built-in defaults when absent. pub fn from_config_dir(dir: &Path) -> Result { - let path = Path::new(&dir.join(format!("{ENGINE_NAME}.json"))); - // TODO TOCTOU, blindly load and return default if ENOENT + let path = dir.join(format!("{ENGINE_NAME}.json")); let cfg: ThresholdConfig = if path.exists() { - crate::config::load_config(path)? + let data = std::fs::read_to_string(&path).map_err(ConfigError::from)?; + serde_json::from_str(&data).map_err(ConfigError::from)? } else { ThresholdConfig::default() };