]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
timeout: ensure infinitesimal timeouts timeout quickly
authorPádraig Brady <P@draigBrady.com>
Fri, 4 Apr 2025 19:40:26 +0000 (20:40 +0100)
committerPádraig Brady <P@draigBrady.com>
Fri, 4 Apr 2025 19:52:32 +0000 (20:52 +0100)
* 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

NEWS
src/timeout.c
tests/timeout/timeout-large-parameters.sh

diff --git a/NEWS b/NEWS
index a77a49f74f204d168b2339274a5ff20271d7cbcd..b4559cefcee62e7b6009cb475c7dac726cb3ec64 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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]
index 578d71070d1f6a86832254ee0bf9411f5fc6835d..6756cd8881695a41db49d8fd45033bcfc429d201 100644 (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;
 }
 
index 5669810e8ab319cc56e6da63a54c9b3743c883f9..a5395d153f70250122c80fb06816567f976f5eb2 100755 (executable)
@@ -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