mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 14:22:52 +08:00
Truncate builtin arguments on NUL
This restores the status quo where builtins are like external commands in that they can't see anything after a 0x00, because that's the c-style string terminator.
This commit is contained in:
parent
41568eb2a8
commit
c7b43b3abf
|
@ -153,7 +153,16 @@ fn rust_run_builtin(
|
|||
status_code: &mut i32,
|
||||
) -> bool {
|
||||
let storage: Vec<WString> = cpp_args.from_ffi();
|
||||
let mut args: Vec<&wstr> = storage.iter().map(|s| s.as_utfstr()).collect();
|
||||
let mut args: Vec<&wstr> = storage
|
||||
.iter()
|
||||
.map(|s| match s.chars().position(|c| c == '\0') {
|
||||
// We truncate on NUL for backwards-compatibility reasons.
|
||||
// This used to be passed as c-strings (`wchar_t *`),
|
||||
// and so we act like it for now.
|
||||
Some(pos) => &s[..pos],
|
||||
None => &s[..],
|
||||
})
|
||||
.collect();
|
||||
let streams = &mut io_streams_t::new(streams);
|
||||
|
||||
match run_builtin(parser.unpin(), streams, args.as_mut_slice(), builtin) {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#RUN: %fish %s
|
||||
# NUL-handling
|
||||
|
||||
# This one actually prints a NUL
|
||||
echo (printf '%s\x00' foo bar | string escape)
|
||||
# CHECK: foo\x00bar\x00
|
||||
# This one is truncated
|
||||
echo foo\x00bar | string escape
|
||||
# CHECK: foo\x00bar
|
||||
# CHECK: foo
|
||||
# This one is just escaped
|
||||
echo foo\\x00bar | string escape
|
||||
# CHECK: foo\\x00bar
|
||||
|
|
Loading…
Reference in New Issue
Block a user