1 From http://ftp.gnu.org/pub/gnu/bash/bash-4.3-patches/bash43-033
3 Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
11 Bug-Reported-by: mickael9@gmail.com, Jan Rome <jan.rome@gmail.com>
12 Bug-Reference-ID: <20140907224046.382ED3610CC@mickael-laptop.localdomain>,
13 <540D661D.50908@gmail.com>
14 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-09/msg00029.html
15 http://lists.gnu.org/archive/html/bug-bash/2014-09/msg00030.html
19 Bash does not clean up the terminal state in all cases where bash or
20 readline modifies it and bash is subsequently terminated by a fatal signal.
21 This happens when the `read' builtin modifies the terminal settings, both
22 when readline is active and when it is not. It occurs most often when a script
23 installs a trap that exits on a signal without re-sending the signal to itself.
25 Patch (apply with `patch -p0'):
27 *** a/bash-4.3-patched/shell.c 2014-01-14 08:04:32.000000000 -0500
28 --- b/shell.c 2014-12-22 10:27:50.000000000 -0500
33 #if defined (READLINE)
34 + # include <readline/readline.h>
35 # include "bashline.h"
42 + /* Clean up the terminal if we are in a state where it's been modified. */
43 + #if defined (READLINE)
44 + if (RL_ISSTATE (RL_STATE_TERMPREPPED) && rl_deprep_term_function)
45 + (*rl_deprep_term_function) ();
47 + if (read_tty_modified ())
48 + read_tty_cleanup ();
50 /* Do trap[0] if defined. Allow it to override the exit status
52 *** a/bash-4.3-patched/builtins/read.def 2014-10-01 12:57:38.000000000 -0400
53 --- b/builtins/read.def 2014-12-22 10:48:54.000000000 -0500
59 static SigHandler *old_alrm;
60 static unsigned char delim;
62 /* In all cases, SIGALRM just sets a flag that we check periodically. This
63 avoids problems with the semi-tricky stuff we do with the xfree of
67 ! static int reading, tty_modified;
68 static SigHandler *old_alrm;
69 static unsigned char delim;
71 + static struct ttsave termsave;
73 /* In all cases, SIGALRM just sets a flag that we check periodically. This
74 avoids problems with the semi-tricky stuff we do with the xfree of
78 TTYSTRUCT ttattrs, ttset;
79 - struct ttsave termsave;
80 #if defined (ARRAY_VARS)
87 ! sigalrm_seen = reading = 0;
89 i = 0; /* Index into the string that we are reading. */
93 ! sigalrm_seen = reading = tty_modified = 0;
95 i = 0; /* Index into the string that we are reading. */
101 + if (interactive_shell == 0)
102 + initialize_terminating_signals ();
103 old_alrm = set_signal_handler (SIGALRM, sigalrm);
104 add_unwind_protect (reset_alarm, (char *)NULL);
111 add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
112 + if (interactive_shell == 0)
113 + initialize_terminating_signals ();
122 add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
123 + if (interactive_shell == 0)
124 + initialize_terminating_signals ();
132 + if (terminating_signal && tty_modified)
133 + ttyrestore (&termsave); /* fix terminal before exiting */
140 ttsetattr (ttp->fd, ttp->attrs);
145 + read_tty_cleanup ()
148 + ttyrestore (&termsave);
152 + read_tty_modified ()
154 + return (tty_modified);
157 *** ./bash-4.3-patched/builtins/common.h 2014-10-01 12:57:47.000000000 -0400
158 --- b/builtins/common.h 2014-12-22 10:10:14.000000000 -0500
162 extern void getopts_reset __P((int));
164 + /* Functions from read.def */
165 + extern void read_tty_cleanup __P((void));
166 + extern int read_tty_modified __P((void));
168 /* Functions from set.def */
169 extern int minus_o_option_value __P((char *));
170 *** a/bash-4.3-patched/bashline.c 2014-05-14 09:22:39.000000000 -0400
171 --- b/bashline.c 2014-09-08 11:28:56.000000000 -0400
175 extern int array_needs_making;
176 extern int posixly_correct, no_symbolic_links;
177 + extern int sigalrm_seen;
178 extern char *current_prompt_string, *ps1_prompt;
179 extern STRING_INT_ALIST word_token_alist[];
182 /* If we're going to longjmp to top_level, make sure we clean up readline.
183 check_signals will call QUIT, which will eventually longjmp to top_level,
184 ! calling run_interrupt_trap along the way. */
185 ! if (interrupt_state)
186 rl_cleanup_after_signal ();
187 bashline_reset_event_hook ();
189 /* If we're going to longjmp to top_level, make sure we clean up readline.
190 check_signals will call QUIT, which will eventually longjmp to top_level,
191 ! calling run_interrupt_trap along the way. The check for sigalrm_seen is
192 ! to clean up the read builtin's state. */
193 ! if (terminating_signal || interrupt_state || sigalrm_seen)
194 rl_cleanup_after_signal ();
195 bashline_reset_event_hook ();
196 *** a/bash-4.3-patched/sig.c 2014-01-10 15:06:06.000000000 -0500
197 --- b/sig.c 2014-09-08 11:26:33.000000000 -0400
200 /* Set the event hook so readline will call it after the signal handlers
201 finish executing, so if this interrupted character input we can get
203 ! if (interactive_shell && interactive && no_line_editing == 0)
204 bashline_set_event_hook ();
207 /* Set the event hook so readline will call it after the signal handlers
208 finish executing, so if this interrupted character input we can get
209 ! quick response. If readline is active or has modified the terminal we
210 ! need to set this no matter what the signal is, though the check for
211 ! RL_STATE_TERMPREPPED is possibly redundant. */
212 ! if (RL_ISSTATE (RL_STATE_SIGHANDLER) || RL_ISSTATE (RL_STATE_TERMPREPPED))
213 bashline_set_event_hook ();
215 *** a/bash-4.3/patchlevel.h 2012-12-29 10:47:57.000000000 -0500
216 --- b/patchlevel.h 2014-03-20 20:01:28.000000000 -0400
219 looks for to find the patch level (for the sccs version string). */
221 ! #define PATCHLEVEL 32
223 #endif /* _PATCHLEVEL_H_ */
225 looks for to find the patch level (for the sccs version string). */
227 ! #define PATCHLEVEL 33
229 #endif /* _PATCHLEVEL_H_ */