Skip to content

Commit 963353a

Browse files
RoyLinRoyLin
authored andcommitted
fix: sanitize krun_env and extra_cmdline in kernel cmdline
Use insert_str_safe() instead of insert_str() for krun_env and windows_kernel_cmdline_append() to prevent InvalidAscii panics when these values contain non-ASCII characters on macOS.
1 parent 64885b6 commit 963353a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/vmm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ pub fn build_microvm(
19571957

19581958
if let Some(cmdline) = &vm_resources.kernel_cmdline.krun_env {
19591959
kernel_cmdline
1960-
.insert_str(cmdline.as_str())
1960+
.insert_str_safe(cmdline.as_str())
19611961
.map_err(|e| {
19621962
// Log the offending string for debugging but convert to a proper error
19631963
// that won't panic - this is cross-platform compatible
@@ -1983,7 +1983,7 @@ pub fn build_microvm(
19831983

19841984
#[cfg(target_os = "windows")]
19851985
if let Some(extra_cmdline) = windows_kernel_cmdline_append() {
1986-
kernel_cmdline.insert_str(extra_cmdline.as_str()).unwrap();
1986+
kernel_cmdline.insert_str_safe(extra_cmdline.as_str()).unwrap();
19871987
}
19881988

19891989
#[cfg(all(not(feature = "tee"), not(target_os = "windows")))]

0 commit comments

Comments
 (0)