diff options
author | Elliott Hughes <enh@google.com> | 2020-10-14 18:08:46 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-15 23:00:46 -0500 |
commit | 6e331aef7f2ce0c6f905ab099028d8cf8f91b1a0 (patch) | |
tree | e24ce081aef7525140a89a4bbdd1064c2aa3a99a /toys | |
parent | f554ce0a4b592272b9171c7c141480a159fa7194 (diff) | |
download | toybox-6e331aef7f2ce0c6f905ab099028d8cf8f91b1a0.tar.gz |
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.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/pending/stty.c | 10 |
1 files changed, 7 insertions, 3 deletions
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<NCCS;j++) { if (sscanf(arg, "%x%n", &value, &n) != 1) error_exit("bad -g string"); |