From 6e331aef7f2ce0c6f905ab099028d8cf8f91b1a0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 14 Oct 2020 18:08:46 -0700 Subject: stty: don't mangle c_iflags. Fixes https://github.com/landley/toybox/issues/251 where `stty 300` was mangling c_iflags to 0x300 because even if we don't match a full hex specification of struct termios, sscanf() will have overwritten the first value, which is c_iflag. --- toys/pending/stty.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'toys') diff --git a/toys/pending/stty.c b/toys/pending/stty.c index 4168b9ba..a997f49d 100644 --- a/toys/pending/stty.c +++ b/toys/pending/stty.c @@ -330,7 +330,7 @@ void stty_main(void) xtcgetattr(&old); if (*toys.optargs) { - struct termios new = old; + struct termios new = old, tmp; for (i=0; toys.optargs[i]; i++) { char *arg = toys.optargs[i]; @@ -340,11 +340,15 @@ void stty_main(void) else if (!strcmp(arg, "line")) new.c_line = get_arg(&i, NR_LDISCS); else if (!strcmp(arg, "min")) new.c_cc[VMIN] = get_arg(&i, 255); else if (!strcmp(arg, "time")) new.c_cc[VTIME] = get_arg(&i, 255); - else if (sscanf(arg, "%x:%x:%x:%x:%n", &new.c_iflag, &new.c_oflag, - &new.c_cflag, &new.c_lflag, &n) == 4) + else if (sscanf(arg, "%x:%x:%x:%x:%n", &tmp.c_iflag, &tmp.c_oflag, + &tmp.c_cflag, &tmp.c_lflag, &n) == 4) { int value; + new.c_iflag = tmp.c_iflag; + new.c_oflag = tmp.c_oflag; + new.c_cflag = tmp.c_cflag; + new.c_lflag = tmp.c_lflag; arg += n; for (j=0;j