From 9fd93a57a62ce7b14db008ff925a3dc9cc73149f Mon Sep 17 00:00:00 2001 From: Navaneeth Yadamreddy Date: Fri, 28 Aug 2026 09:24:28 +0530 Subject: [PATCH] stty: verify tcsetattr applied all requested settings POSIX allows tcsetattr to succeed while only partially applying changes. GNU stty re-reads terminal settings after tcsetattr and compares them to the requested configuration, exiting with an error if they differ. uutils previously called tcsetattr and returned success without verification. Fixes #10324 --- src/uu/stty/src/stty.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 193c863c3d3..a5c3b1f8dfd 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -437,6 +437,20 @@ fn stty(opts: &Options) -> UResult<()> { } } tcsetattr(opts.file.as_fd(), set_arg, &termios)?; + + // Verify that tcsetattr actually applied all requested settings. + // POSIX allows tcsetattr to succeed while only partially applying + // changes. GNU stty re-reads and compares; we do the same. + let actual = tcgetattr(opts.file.as_fd()).map_err_context(|| opts.device_name.clone())?; + if actual != termios { + return Err(USimpleError::new( + 1, + format!( + "{0}: unable to perform all requested tcsetattr operations", + opts.device_name + ), + )); + } } else { let termios = tcgetattr(opts.file.as_fd()).map_err_context(|| opts.device_name.clone())?; print_settings(&termios, opts)?;