`read' stores the return value from tcsetattr in a variable that
is later used as an index into input_string.
$ (trap '' TTIN; trap : TTOU; read -n1) &
read: error setting terminal attributes: Interrupted system call
=================================================================
ERROR: AddressSanitizer: heap-buffer-overflow on address ...
WRITE of size 1 at 0x60b00000423f thread T0
#0 0x00010047bff0 in read_builtin read.def:924
---
builtins/read.def | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/builtins/read.def b/builtins/read.def
index 4ad36325..756fb3ff 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -622,9 +622,9 @@ read_builtin (WORD_LIST *list)
termsave.attrs = ttattrs;
ttset = ttattrs;
- i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset);
- if (i < 0)
+ if ((silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset)) <
0)
sh_ttyerror (1);
+
tty_modified = 1;
add_unwind_protect (uw_ttyrestore, &termsave);
if (interactive_shell == 0)
@@ -639,8 +639,7 @@ read_builtin (WORD_LIST *list)
termsave.attrs = ttattrs;
ttset = ttattrs;
- i = ttfd_noecho (fd, &ttset); /* ttnoecho (); */
- if (i < 0)
+ if (ttfd_noecho (fd, &ttset) < 0) /* ttnoecho ();
*/
sh_ttyerror (1);
tty_modified = 1;
--
2.51.0