timeout: ensure infinitesimal timeouts timeout quickly

* src/timeout.c (parse_duration): Clamp infinitesimal values to 1ns.
* tests/timeout/timeout-large-parameters.sh: Add a test case.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/77535
This commit is contained in:
Pádraig Brady
2025-04-04 20:40:26 +01:00
parent 9ed5770b5e
commit 026d0d7c40
3 changed files with 11 additions and 0 deletions

4
NEWS
View File

@@ -23,6 +23,10 @@ GNU coreutils NEWS -*- outline -*-
like with dangling symlinks on cygwin.
[bug introduced in coreutils-9.6]
timeout would fail to timeout commands with infinitesimal timeouts.
For example `timeout 1e-5000 sleep inf` would never timeout.
[bug introduced with timeout in coreutils-7.0]
'who -m' now outputs entries for remote logins. Previously login
entries prefixed with the service (like "sshd") were not matched.
[bug introduced in coreutils-9.4]

View File

@@ -371,6 +371,10 @@ parse_duration (char const *str)
usage (EXIT_CANCELED);
}
/* Clamp underflow to 1ns, as 0 disables the timeout. */
if (duration == 0 && errno == ERANGE)
duration = 1e-9;
return duration;
}

View File

@@ -43,4 +43,7 @@ timeout 2.34e+5d sleep 0 || fail=1
timeout $LDBL_MAX sleep 0 || fail=1
returns_ 125 timeout -- -$LDBL_MAX sleep 0 || fail=1
# Ensure underflow times out immediately
returns_ 124 timeout 1e-5000 sleep 10 || fail=1
Exit $fail