1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

env: don't allow '=' with -u (#7008)

* Added error handling to ensure '=' after -u returns 125 as '=' is not allowed

* Added tests for disallow = on short options

* Added error handling to ensure '=' after -u returns 125 as '=' is not allowed

* Added tests for disallow = on short options

* Disallow only short unset option from having '=' as its starting character

* Remove needless tests and update function name for clarity
This commit is contained in:
jovie :) 2024-12-31 01:16:14 -07:00 committed by GitHub
parent d81d893964
commit 646fc394f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

13
src/uu/env/src/env.rs vendored
View file

@ -370,6 +370,19 @@ impl EnvAppData {
self.had_string_argument = true;
}
_ => {
let arg_str = arg.to_string_lossy();
// Short unset option (-u) is not allowed to contain '='
if arg_str.contains('=')
&& arg_str.starts_with("-u")
&& !arg_str.starts_with("--")
{
return Err(USimpleError::new(
125,
format!("cannot unset '{}': Invalid argument", &arg_str[2..]),
));
}
all_args.push(arg.clone());
}
}

View file

@ -882,6 +882,29 @@ fn test_env_arg_ignore_signal_empty() {
.no_stderr()
.stdout_contains("hello");
}
#[test]
fn disallow_equals_sign_on_short_unset_option() {
let ts = TestScenario::new(util_name!());
ts.ucmd()
.arg("-u=")
.fails()
.code_is(125)
.stderr_contains("env: cannot unset '=': Invalid argument");
ts.ucmd()
.arg("-u=A1B2C3")
.fails()
.code_is(125)
.stderr_contains("env: cannot unset '=A1B2C3': Invalid argument");
ts.ucmd().arg("--split-string=A1B=2C3=").succeeds();
ts.ucmd()
.arg("--unset=")
.fails()
.code_is(125)
.stderr_contains("env: cannot unset '': Invalid argument");
}
#[cfg(test)]
mod tests_split_iterator {