diff --git a/apps/system/components/ProcessManager/kata-proc-interface/Cargo.toml b/apps/system/components/ProcessManager/kata-proc-interface/Cargo.toml index 267dac4..1fc5497 100644 --- a/apps/system/components/ProcessManager/kata-proc-interface/Cargo.toml +++ b/apps/system/components/ProcessManager/kata-proc-interface/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -cstr_core = { version = "0.2.3", default-features = false } +cstr_core = "0.2.3" kata-security-interface = { path = "../../SecurityCoordinator/kata-security-interface" } postcard = { version = "0.7", features = ["alloc"], default-features = false } serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } diff --git a/apps/system/components/ProcessManager/kata-proc-interface/src/lib.rs b/apps/system/components/ProcessManager/kata-proc-interface/src/lib.rs index ca40971..4384cca 100644 --- a/apps/system/components/ProcessManager/kata-proc-interface/src/lib.rs +++ b/apps/system/components/ProcessManager/kata-proc-interface/src/lib.rs @@ -6,6 +6,7 @@ extern crate alloc; use alloc::string::String; use alloc::vec::Vec; use core::str; +use cstr_core::CString; use kata_security_interface::SecurityRequestError; use postcard; use serde::{Deserialize, Serialize}; @@ -152,6 +153,12 @@ impl From for ProcessManagerError { } } +impl From for ProcessManagerError { + fn from(_err: cstr_core::NulError) -> ProcessManagerError { + ProcessManagerError::BundleIdInvalid + } +} + impl From for Result<(), ProcessManagerError> { fn from(err: ProcessManagerError) -> Result<(), ProcessManagerError> { if err == ProcessManagerError::Success { @@ -204,7 +211,8 @@ pub fn kata_pkg_mgmt_uninstall(bundle_id: &str) -> Result<(), ProcessManagerErro extern "C" { fn pkg_mgmt_uninstall(c_bundle_id: *const cstr_core::c_char) -> ProcessManagerError; } - unsafe { pkg_mgmt_uninstall(bundle_id.as_ptr()) }.into() + let cstr = CString::new(bundle_id)?; + unsafe { pkg_mgmt_uninstall(cstr.as_ptr()) }.into() } #[inline] @@ -213,7 +221,8 @@ pub fn kata_proc_ctrl_start(bundle_id: &str) -> Result<(), ProcessManagerError> extern "C" { fn proc_ctrl_start(c_bundle_id: *const cstr_core::c_char) -> ProcessManagerError; } - unsafe { proc_ctrl_start(bundle_id.as_ptr()) }.into() + let cstr = CString::new(bundle_id)?; + unsafe { proc_ctrl_start(cstr.as_ptr()) }.into() } #[inline] @@ -222,7 +231,8 @@ pub fn kata_proc_ctrl_stop(bundle_id: &str) -> Result<(), ProcessManagerError> { extern "C" { fn proc_ctrl_stop(c_bundle_id: *const cstr_core::c_char) -> ProcessManagerError; } - unsafe { proc_ctrl_stop(bundle_id.as_ptr()) }.into() + let cstr = CString::new(bundle_id)?; + unsafe { proc_ctrl_stop(cstr.as_ptr()) }.into() } // TODO(sleffler): move out of interface?