Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion stdlib/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ fn process_run(
RuntimeValue::List { items, .. } => {
let mut list = Vec::new();
for item in items.borrow().iter() {
list.push(item.try_into_string()?);
let s = item.try_into_string()?;
if s.contains('\0') {
return Err(RuntimeError::new(
RuntimeErrorKind::InvalidOperation(
"Security policy violation: Null bytes in command arguments are denied"
.to_string(),
),
None,
None,
));
}
list.push(s);
}
list
}
Expand Down
19 changes: 19 additions & 0 deletions stdlib/tests/stdlib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,25 @@ fn test_system_diagnostics_and_process_execution() {
} else {
panic!("run did not return a Map");
}

// 3. Verify process.run rejects null bytes in arguments
let null_arg_res = run.call(
&mut ctx,
vec![
RuntimeValue::Str(cmd.to_string()),
RuntimeValue::List {
items: Rc::new(RefCell::new(vec![RuntimeValue::Str(
"hello\0world".to_string(),
)])),
is_const: false,
},
],
);
assert!(null_arg_res.is_err());
assert!(null_arg_res
.unwrap_err()
.to_string()
.contains("Security policy violation: Null bytes in command arguments are denied"));
}

#[test]
Expand Down
Loading