The first is an info doc adjustment to remove explicit mention of speeds
which could now be incomplete and also mention support for arbitrary speeds.

The second adjusts speed parsing to disallow extraneous chars after floats.
For example "9600.0bps" or "9600.0x2" were allowed before this change.

I'll push these later if there are no objections.

cheers,
Padraig.
From 8b05eca972f70858749a946ac24f08d0718c1be6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Sun, 22 Jun 2025 15:01:21 +0100
Subject: [PATCH 1/2] doc: stty: adjust description of supported speeds

* doc/coreutils.texi (stty invocation): Remove now imprecise
list of speeds given we may now support higher or arbitrary speeds.
Mention that we may support higher or arbitrary speeds.
---
 doc/coreutils.texi | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index fc62c6d8d..a1d45fb30 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -15925,25 +15925,8 @@ Print the terminal speed.
 Set the input and output speeds to @var{n}.  @var{n} can be one of: 0
 50 75 110 134 134.5 150 200 300 600 1200 1800 2400 4800 9600 19200
 38400 @code{exta} @code{extb}.  @code{exta} is the same as 19200;
-@code{extb} is the same as 38400.  Many systems, including GNU/Linux,
-support higher speeds.  The @command{stty} command includes support
-for speeds of
-57600,
-115200,
-230400,
-460800,
-500000,
-576000,
-921600,
-1000000,
-1152000,
-1500000,
-2000000,
-2500000,
-3000000,
-3500000,
-or
-4000000 where the system supports these.
+@code{extb} is the same as 38400.  Many systems, support arbitrary
+or higher speeds.
 0 hangs up the line if @option{-clocal} is set.
 @end table
 
-- 
2.49.0

From 08fea80b3cccacd2aec2f2c97b8e2aa8a8160cd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Sun, 22 Jun 2025 16:40:04 +0100
Subject: [PATCH 2/2] stty: stricter floating point parsing

* src/stty.c (string_to_baud): Disallow extraneous characters
after floating point numbers.
* tests/stty/stty-invalid.sh: Add test cases.
---
 src/stty.c                 | 27 +++++++++++++--------------
 tests/stty/stty-invalid.sh |  3 ++-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/stty.c b/src/stty.c
index 561de1c1a..0163ea48a 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -2200,25 +2200,24 @@ string_to_baud (char const *arg)
       c = *ep++;
       if (c)
         {
-          c -= '0';
-          if (c > 9)
+          unsigned char d = c - '0';
+          if (d > 5)
+            value++;
+          else if (d == 5)
             {
-              return (speed_t) -1; /* Garbage after otherwise valid number */
-            }
-          else if (c > 5)
-            {
-              value++;
-            }
-          else if (c == 5)
-            {
-              while ((c = *ep++) == '0')
-              ; /* Skip zeroes after .5 */
+              while ((c = *ep++) == '0'); /* Skip zeroes after .5 */
 
-              if (c >= '1' && c <= '9')
-                value++;                /* Nonzero digit, round up */
+              if (c)
+                value++;                /* Nonzero, round up */
               else
                 value += (value & 1);   /* Exactly in the middle, round even */
             }
+
+          while (c_isdigit (c)) /* Skip remaining digits.  */
+            c = *ep++;
+
+          if (c)
+            return (speed_t) -1; /* Garbage after otherwise valid number */
         }
     }
   else if (c)
diff --git a/tests/stty/stty-invalid.sh b/tests/stty/stty-invalid.sh
index a1442a82d..3cede5069 100755
--- a/tests/stty/stty-invalid.sh
+++ b/tests/stty/stty-invalid.sh
@@ -55,7 +55,8 @@ fi
 # so restrict tests here to invalid numbers
 # We simulate unsupported numbers in a separate "LD_PRELOAD" test.
 WRAP_9600="$(expr $ULONG_OFLOW - 9600)"
-for speed in 9600.. ++9600 -$WRAP_9600 --$WRAP_9600 0x2580 96E2; do
+for speed in 9599.. 9600.. 9600.5. 9600.50. 9600.0. ++9600 \
+             -$WRAP_9600 --$WRAP_9600 0x2580 96E2 9600,0; do
   returns_ 1 stty ispeed "$speed" || fail=1
 done
 
-- 
2.49.0

Reply via email to