]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stty: ensure arbitrary data is not displayed
authorPádraig Brady <P@draigBrady.com>
Sun, 19 Mar 2023 22:22:18 +0000 (22:22 +0000)
committerPádraig Brady <P@draigBrady.com>
Sun, 19 Mar 2023 22:25:50 +0000 (22:25 +0000)
* src/stty.c (main): Use static structures to ensure
they're initialized (to zero), so that random data is
not displayed, or compared resulting in a inaccurate
failure reported to users.  This was seen on musl libc
where some parts of the termios c_cc array were
not initialized by tcgetattr().
Reported by Bruno Haible.

src/stty.c

index fb7feefaba8c71a9cc01be06d149273b6ba0350b..607a4e7bb3410763499e4c748e1f1882e49990dc 100644 (file)
@@ -1290,7 +1290,9 @@ apply_settings (bool checking, char const *device_name,
 int
 main (int argc, char **argv)
 {
-  struct termios mode;
+  /* Initialize to all zeroes so there is no risk memcmp will report a
+     spurious difference in an uninitialized portion of the structure.  */
+  static struct termios mode;
 
   enum output_type output_type;
   int optc;
@@ -1426,7 +1428,9 @@ main (int argc, char **argv)
 
   if (require_set_attr)
     {
-      struct termios new_mode;
+      /* Initialize to all zeroes so there is no risk memcmp will report a
+         spurious difference in an uninitialized portion of the structure.  */
+      static struct termios new_mode;
 
       if (tcsetattr (STDIN_FILENO, tcsetattr_options, &mode))
         die (EXIT_FAILURE, errno, "%s", quotef (device_name));