Merge branch 'main' into bug/cp-preserve-xattr-9704

This commit is contained in:
nirv 2025-12-19 15:40:07 +05:30 committed by GitHub
commit 655cf52aac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 9 deletions

View file

@ -487,6 +487,7 @@ pub fn uu_app() -> Command {
.short('s')
.long(OPT_SET)
.value_name("STRING")
.allow_hyphen_values(true)
.help({
#[cfg(not(any(target_os = "macos", target_os = "redox")))]
{

View file

@ -137,8 +137,8 @@ pub fn uu_app() -> Command {
}
fn handle_obsolete(args: &mut Vec<String>) -> Option<usize> {
// Sanity check
if args.len() > 2 {
// Sanity check - need at least the program name and one argument
if args.len() >= 2 {
// Old signal can only be in the first argument position
let slice = args[1].as_str();
if let Some(signal) = slice.strip_prefix('-') {

View file

@ -595,14 +595,10 @@ fn eat_number(rest: &mut &[u8], index: &mut usize) -> Option<usize> {
match rest[*index..].iter().position(|b| !b.is_ascii_digit()) {
None | Some(0) => None,
Some(i) => {
// TODO: This might need to handle errors better
// For example in case of overflow.
let parsed = std::str::from_utf8(&rest[*index..(*index + i)])
.unwrap()
.parse()
.unwrap();
// Handle large numbers that would cause overflow
let num_str = std::str::from_utf8(&rest[*index..(*index + i)]).unwrap();
*index += i;
Some(parsed)
Some(num_str.parse().unwrap_or(usize::MAX))
}
}
}

View file

@ -293,6 +293,27 @@ fn test_date_set_permissions_error() {
}
}
#[test]
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
fn test_date_set_hyphen_prefixed_values() {
// test -s flag accepts hyphen-prefixed values like "-3 days"
if !(geteuid() == 0 || uucore::os::is_wsl_1()) {
let test_cases = vec!["-1 hour", "-2 days", "-3 weeks", "-1 month"];
for date_str in test_cases {
let result = new_ucmd!().arg("--set").arg(date_str).fails();
result.no_stdout();
// permission error, not argument parsing error
assert!(
result.stderr_str().starts_with("date: cannot set date: "),
"Expected permission error for '{}', but got: {}",
date_str,
result.stderr_str()
);
}
}
}
#[test]
#[cfg(target_os = "macos")]
fn test_date_set_mac_unavailable() {

View file

@ -395,3 +395,27 @@ fn test_kill_with_signal_and_table() {
.arg("-t")
.fails();
}
/// Test that `kill -1` (signal without PID) reports "no process ID" error
/// instead of being misinterpreted as pid=-1 which would kill all processes.
/// This matches GNU kill behavior.
#[test]
fn test_kill_signal_only_no_pid() {
// Test with -1 (SIGHUP)
new_ucmd!()
.arg("-1")
.fails()
.stderr_contains("no process ID specified");
// Test with -9 (SIGKILL)
new_ucmd!()
.arg("-9")
.fails()
.stderr_contains("no process ID specified");
// Test with -TERM
new_ucmd!()
.arg("-TERM")
.fails()
.stderr_contains("no process ID specified");
}

View file

@ -1482,3 +1482,13 @@ fn test_large_width_format() {
.stdout_is("");
}
}
#[test]
fn test_extreme_field_width_overflow() {
// Test the specific case that was causing panic due to integer overflow
// in the field width parsing.
new_ucmd!()
.args(&["%999999999999999999999999d", "1"])
.fails_with_code(1)
.stderr_only("printf: write error\n");
}