* src/stty.c (string_to_baud): Disallow empty speeds.
* tests/stty/stty-invalid.sh: Add checks.
* NEWS: Mention the bug fix.

Link: https://github.com/coreutils/coreutils/issues/380
---
 NEWS                       | 4 ++++
 src/stty.c                 | 4 ++++
 tests/stty/stty-invalid.sh | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 5292a53c3..60fc624cc 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   resolves to a path beginning with the symbolic link itself.
   [bug introduced in coreutils-9.0]
 
+  'stty' again rejects empty speed arguments.
+  Previously such arguments were accepted as value 0.
+  [bug introduced in coreutils-9.8]
+
   'unexpand' no longer overflows a heap buffer on non-GLIBC platforms,
   given whitespace characters whose display width is negative.  E.g.,
   this edge case can occur with \u0085 (next line) characters on musl.
diff --git a/src/stty.c b/src/stty.c
index 0d12642be..0be2dd6bc 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -2265,6 +2265,10 @@ string_to_baud (char const *arg)
   if (*arg == '-')
     return (speed_t) -1;
 
+  /* Empty does not mean 0.  */
+  if (! *arg)
+    return (speed_t) -1;
+
   value = strtoul (arg, &ep, 10);
 
   c = *ep++;
diff --git a/tests/stty/stty-invalid.sh b/tests/stty/stty-invalid.sh
index 46d39bfa4..c85f0f125 100755
--- a/tests/stty/stty-invalid.sh
+++ b/tests/stty/stty-invalid.sh
@@ -56,7 +56,7 @@ fi
 # We simulate unsupported numbers in a separate "LD_PRELOAD" test.
 WRAP_9600="$(expr $ULONG_OFLOW - 9600)"
 for speed in 9599.. 9600.. 9600.5. 9600.50. 9600.0. ++9600 \
-             -$WRAP_9600 --$WRAP_9600 0x2580 96E2 9600,0 '9600.0 '; do
+             -$WRAP_9600 --$WRAP_9600 0x2580 96E2 9600,0 '9600.0 ' '' ' '; do
   returns_ 1 stty ispeed "$speed" || fail=1
 done
 
-- 
2.55.0


Reply via email to