0033-patchlevel-33.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. From http://ftp.gnu.org/pub/gnu/bash/bash-4.3-patches/bash43-033
  2. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
  3. BASH PATCH REPORT
  4. =================
  5. Bash-Release: 4.3
  6. Patch-ID: bash43-033
  7. Bug-Reported-by: mickael9@gmail.com, Jan Rome <jan.rome@gmail.com>
  8. Bug-Reference-ID: <20140907224046.382ED3610CC@mickael-laptop.localdomain>,
  9. <540D661D.50908@gmail.com>
  10. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2014-09/msg00029.html
  11. http://lists.gnu.org/archive/html/bug-bash/2014-09/msg00030.html
  12. Bug-Description:
  13. Bash does not clean up the terminal state in all cases where bash or
  14. readline modifies it and bash is subsequently terminated by a fatal signal.
  15. This happens when the `read' builtin modifies the terminal settings, both
  16. when readline is active and when it is not. It occurs most often when a script
  17. installs a trap that exits on a signal without re-sending the signal to itself.
  18. Patch (apply with `patch -p0'):
  19. *** a/bash-4.3-patched/shell.c 2014-01-14 08:04:32.000000000 -0500
  20. --- b/shell.c 2014-12-22 10:27:50.000000000 -0500
  21. ***************
  22. *** 74,77 ****
  23. --- 74,78 ----
  24. #if defined (READLINE)
  25. + # include <readline/readline.h>
  26. # include "bashline.h"
  27. #endif
  28. ***************
  29. *** 910,913 ****
  30. --- 912,923 ----
  31. fflush (stderr);
  32. + /* Clean up the terminal if we are in a state where it's been modified. */
  33. + #if defined (READLINE)
  34. + if (RL_ISSTATE (RL_STATE_TERMPREPPED) && rl_deprep_term_function)
  35. + (*rl_deprep_term_function) ();
  36. + #endif
  37. + if (read_tty_modified ())
  38. + read_tty_cleanup ();
  39. +
  40. /* Do trap[0] if defined. Allow it to override the exit status
  41. passed to us. */
  42. *** a/bash-4.3-patched/builtins/read.def 2014-10-01 12:57:38.000000000 -0400
  43. --- b/builtins/read.def 2014-12-22 10:48:54.000000000 -0500
  44. ***************
  45. *** 141,148 ****
  46. int sigalrm_seen;
  47. ! static int reading;
  48. static SigHandler *old_alrm;
  49. static unsigned char delim;
  50. /* In all cases, SIGALRM just sets a flag that we check periodically. This
  51. avoids problems with the semi-tricky stuff we do with the xfree of
  52. --- 141,150 ----
  53. int sigalrm_seen;
  54. ! static int reading, tty_modified;
  55. static SigHandler *old_alrm;
  56. static unsigned char delim;
  57. + static struct ttsave termsave;
  58. +
  59. /* In all cases, SIGALRM just sets a flag that we check periodically. This
  60. avoids problems with the semi-tricky stuff we do with the xfree of
  61. ***************
  62. *** 189,193 ****
  63. SHELL_VAR *var;
  64. TTYSTRUCT ttattrs, ttset;
  65. - struct ttsave termsave;
  66. #if defined (ARRAY_VARS)
  67. WORD_LIST *alist;
  68. --- 191,194 ----
  69. ***************
  70. *** 222,226 ****
  71. USE_VAR(lastsig);
  72. ! sigalrm_seen = reading = 0;
  73. i = 0; /* Index into the string that we are reading. */
  74. --- 223,227 ----
  75. USE_VAR(lastsig);
  76. ! sigalrm_seen = reading = tty_modified = 0;
  77. i = 0; /* Index into the string that we are reading. */
  78. ***************
  79. *** 439,442 ****
  80. --- 440,445 ----
  81. goto assign_vars;
  82. }
  83. + if (interactive_shell == 0)
  84. + initialize_terminating_signals ();
  85. old_alrm = set_signal_handler (SIGALRM, sigalrm);
  86. add_unwind_protect (reset_alarm, (char *)NULL);
  87. ***************
  88. *** 483,487 ****
  89. --- 486,493 ----
  90. if (i < 0)
  91. sh_ttyerror (1);
  92. + tty_modified = 1;
  93. add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
  94. + if (interactive_shell == 0)
  95. + initialize_terminating_signals ();
  96. }
  97. }
  98. ***************
  99. *** 498,502 ****
  100. --- 504,511 ----
  101. sh_ttyerror (1);
  102. + tty_modified = 1;
  103. add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
  104. + if (interactive_shell == 0)
  105. + initialize_terminating_signals ();
  106. }
  107. ***************
  108. *** 589,592 ****
  109. --- 598,603 ----
  110. else
  111. lastsig = 0;
  112. + if (terminating_signal && tty_modified)
  113. + ttyrestore (&termsave); /* fix terminal before exiting */
  114. CHECK_TERMSIG;
  115. eof = 1;
  116. ***************
  117. *** 979,982 ****
  118. --- 990,1007 ----
  119. {
  120. ttsetattr (ttp->fd, ttp->attrs);
  121. + tty_modified = 0;
  122. + }
  123. +
  124. + void
  125. + read_tty_cleanup ()
  126. + {
  127. + if (tty_modified)
  128. + ttyrestore (&termsave);
  129. + }
  130. +
  131. + int
  132. + read_tty_modified ()
  133. + {
  134. + return (tty_modified);
  135. }
  136. *** ./bash-4.3-patched/builtins/common.h 2014-10-01 12:57:47.000000000 -0400
  137. --- b/builtins/common.h 2014-12-22 10:10:14.000000000 -0500
  138. ***************
  139. *** 123,126 ****
  140. --- 141,148 ----
  141. extern void getopts_reset __P((int));
  142. + /* Functions from read.def */
  143. + extern void read_tty_cleanup __P((void));
  144. + extern int read_tty_modified __P((void));
  145. +
  146. /* Functions from set.def */
  147. extern int minus_o_option_value __P((char *));
  148. *** a/bash-4.3-patched/bashline.c 2014-05-14 09:22:39.000000000 -0400
  149. --- b/bashline.c 2014-09-08 11:28:56.000000000 -0400
  150. ***************
  151. *** 203,206 ****
  152. --- 203,207 ----
  153. extern int array_needs_making;
  154. extern int posixly_correct, no_symbolic_links;
  155. + extern int sigalrm_seen;
  156. extern char *current_prompt_string, *ps1_prompt;
  157. extern STRING_INT_ALIST word_token_alist[];
  158. ***************
  159. *** 4209,4214 ****
  160. /* If we're going to longjmp to top_level, make sure we clean up readline.
  161. check_signals will call QUIT, which will eventually longjmp to top_level,
  162. ! calling run_interrupt_trap along the way. */
  163. ! if (interrupt_state)
  164. rl_cleanup_after_signal ();
  165. bashline_reset_event_hook ();
  166. --- 4262,4268 ----
  167. /* If we're going to longjmp to top_level, make sure we clean up readline.
  168. check_signals will call QUIT, which will eventually longjmp to top_level,
  169. ! calling run_interrupt_trap along the way. The check for sigalrm_seen is
  170. ! to clean up the read builtin's state. */
  171. ! if (terminating_signal || interrupt_state || sigalrm_seen)
  172. rl_cleanup_after_signal ();
  173. bashline_reset_event_hook ();
  174. *** a/bash-4.3-patched/sig.c 2014-01-10 15:06:06.000000000 -0500
  175. --- b/sig.c 2014-09-08 11:26:33.000000000 -0400
  176. ***************
  177. *** 533,538 ****
  178. /* Set the event hook so readline will call it after the signal handlers
  179. finish executing, so if this interrupted character input we can get
  180. ! quick response. */
  181. ! if (interactive_shell && interactive && no_line_editing == 0)
  182. bashline_set_event_hook ();
  183. #endif
  184. --- 533,540 ----
  185. /* Set the event hook so readline will call it after the signal handlers
  186. finish executing, so if this interrupted character input we can get
  187. ! quick response. If readline is active or has modified the terminal we
  188. ! need to set this no matter what the signal is, though the check for
  189. ! RL_STATE_TERMPREPPED is possibly redundant. */
  190. ! if (RL_ISSTATE (RL_STATE_SIGHANDLER) || RL_ISSTATE (RL_STATE_TERMPREPPED))
  191. bashline_set_event_hook ();
  192. #endif
  193. *** a/bash-4.3/patchlevel.h 2012-12-29 10:47:57.000000000 -0500
  194. --- b/patchlevel.h 2014-03-20 20:01:28.000000000 -0400
  195. ***************
  196. *** 26,30 ****
  197. looks for to find the patch level (for the sccs version string). */
  198. ! #define PATCHLEVEL 32
  199. #endif /* _PATCHLEVEL_H_ */
  200. --- 26,30 ----
  201. looks for to find the patch level (for the sccs version string). */
  202. ! #define PATCHLEVEL 33
  203. #endif /* _PATCHLEVEL_H_ */