bash52-015.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. BASH PATCH REPORT
  2. =================
  3. Bash-Release: 5.2
  4. Patch-ID: bash52-015
  5. Bug-Reported-by: Frode Nordahl <frode.nordahl@canonical.com>
  6. Bug-Reference-ID: <20221119070714.351759-1-frode.nordahl@canonical.com>
  7. Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2022-11/msg00078.html
  8. Bug-Description:
  9. There are several cases where bash is too aggressive when optimizing out forks
  10. in subshells. For example, `eval' and traps should never be optimized.
  11. Patch (apply with `patch -p0'):
  12. *** ../bash-5.2-patched/builtins/common.h 2022-11-23 17:09:18.000000000 -0500
  13. --- builtins/common.h 2022-11-19 18:03:59.000000000 -0500
  14. ***************
  15. *** 52,55 ****
  16. --- 52,56 ----
  17. #define SEVAL_ONECMD 0x100 /* only allow a single command */
  18. #define SEVAL_NOHISTEXP 0x200 /* inhibit history expansion */
  19. + #define SEVAL_NOOPTIMIZE 0x400 /* don't try to set optimization flags */
  20. /* Flags for describe_command, shared between type.def and command.def */
  21. *** ../bash-5.2-patched/builtins/evalstring.c 2022-11-05 17:27:44.000000000 -0400
  22. --- builtins/evalstring.c 2022-11-19 18:23:21.000000000 -0500
  23. ***************
  24. *** 133,138 ****
  25. (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
  26. (command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
  27. ! ((startup_state == 2 && should_suppress_fork (command->value.Connection->second)) ||
  28. ! ((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
  29. {
  30. command->value.Connection->second->flags |= CMD_NO_FORK;
  31. --- 133,138 ----
  32. (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
  33. (command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
  34. ! (should_suppress_fork (command->value.Connection->second) ||
  35. ! ((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
  36. {
  37. command->value.Connection->second->flags |= CMD_NO_FORK;
  38. ***************
  39. *** 291,294 ****
  40. --- 291,295 ----
  41. (flags & SEVAL_RESETLINE) -> reset line_number to 1
  42. (flags & SEVAL_NOHISTEXP) -> history_expansion_inhibited -> 1
  43. + (flags & SEVAL_NOOPTIMIZE) -> don't try to turn on optimizing flags
  44. */
  45. ***************
  46. *** 503,507 ****
  47. series of connection commands is
  48. command->value.Connection->second. */
  49. ! else if (command->type == cm_connection && can_optimize_connection (command))
  50. {
  51. command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
  52. --- 504,510 ----
  53. series of connection commands is
  54. command->value.Connection->second. */
  55. ! else if (command->type == cm_connection &&
  56. ! (flags & SEVAL_NOOPTIMIZE) == 0 &&
  57. ! can_optimize_connection (command))
  58. {
  59. command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
  60. *** ../bash-5.2-patched/builtins/eval.def 2016-01-25 13:28:37.000000000 -0500
  61. --- builtins/eval.def 2022-11-19 18:04:25.000000000 -0500
  62. ***************
  63. *** 54,57 ****
  64. list = loptend; /* skip over possible `--' */
  65. ! return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST) : EXECUTION_SUCCESS);
  66. }
  67. --- 54,57 ----
  68. list = loptend; /* skip over possible `--' */
  69. ! return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST|SEVAL_NOOPTIMIZE) : EXECUTION_SUCCESS);
  70. }
  71. *** ../bash-5.2-patched/trap.c 2022-08-10 08:59:45.000000000 -0400
  72. --- trap.c 2022-12-12 10:57:51.000000000 -0500
  73. ***************
  74. *** 305,308 ****
  75. --- 305,309 ----
  76. volatile int save_return_catch_flag, function_code;
  77. procenv_t save_return_catch;
  78. + char *trap_command, *old_trap;
  79. #if defined (ARRAY_VARS)
  80. ARRAY *ps;
  81. ***************
  82. *** 420,423 ****
  83. --- 421,427 ----
  84. else
  85. {
  86. + old_trap = trap_list[sig];
  87. + trap_command = savestring (old_trap);
  88. +
  89. save_parser_state (&pstate);
  90. save_subst_varlist = subst_assign_varlist;
  91. ***************
  92. *** 442,446 ****
  93. if (function_code == 0)
  94. ! x = parse_and_execute (savestring (trap_list[sig]), "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
  95. else
  96. {
  97. --- 446,451 ----
  98. if (function_code == 0)
  99. ! /* XXX is x always last_command_exit_value? */
  100. ! x = parse_and_execute (trap_command, "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
  101. else
  102. {
  103. ***************
  104. *** 1003,1007 ****
  105. {
  106. reset_parser ();
  107. ! parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
  108. }
  109. else if (code == ERREXIT)
  110. --- 1008,1012 ----
  111. {
  112. reset_parser ();
  113. ! parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
  114. }
  115. else if (code == ERREXIT)
  116. ***************
  117. *** 1110,1114 ****
  118. }
  119. ! flags = SEVAL_NONINT|SEVAL_NOHIST;
  120. if (sig != DEBUG_TRAP && sig != RETURN_TRAP && sig != ERROR_TRAP)
  121. flags |= SEVAL_RESETLINE;
  122. --- 1115,1119 ----
  123. }
  124. ! flags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE;
  125. if (sig != DEBUG_TRAP && sig != RETURN_TRAP && sig != ERROR_TRAP)
  126. flags |= SEVAL_RESETLINE;
  127. *** ../bash-5.2-patched/parse.y 2022-11-23 17:09:18.000000000 -0500
  128. --- parse.y 2022-11-19 18:15:34.000000000 -0500
  129. ***************
  130. *** 2828,2832 ****
  131. last_lastarg = savestring (last_lastarg);
  132. ! parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
  133. restore_parser_state (&ps);
  134. --- 2844,2848 ----
  135. last_lastarg = savestring (last_lastarg);
  136. ! parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE);
  137. restore_parser_state (&ps);
  138. *** ../bash-5.2-patched/jobs.c 2022-07-18 10:19:56.000000000 -0400
  139. --- jobs.c 2022-11-19 18:10:24.000000000 -0500
  140. ***************
  141. *** 4221,4225 ****
  142. for (i = 0; i < nchild; i++)
  143. {
  144. ! parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE);
  145. }
  146. --- 4243,4247 ----
  147. for (i = 0; i < nchild; i++)
  148. {
  149. ! parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
  150. }
  151. *** ../bash-5.2-patched/y.tab.c 2022-11-23 17:09:18.000000000 -0500
  152. --- y.tab.c 2022-11-23 17:21:17.000000000 -0500
  153. ***************
  154. *** 5139,5143 ****
  155. last_lastarg = savestring (last_lastarg);
  156. ! parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
  157. restore_parser_state (&ps);
  158. --- 5154,5158 ----
  159. last_lastarg = savestring (last_lastarg);
  160. ! parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE);
  161. restore_parser_state (&ps);
  162. *** ../bash-5.2-patched/execute_cmd.c 2022-11-05 17:27:41.000000000 -0400
  163. --- execute_cmd.c 2022-11-22 17:09:38.000000000 -0500
  164. ***************
  165. *** 1655,1659 ****
  166. and set CMD_TRY_OPTIMIZING for simple commands on the right side of an
  167. and-or or `;' list to test for optimizing forks when they are executed. */
  168. ! if (user_subshell && command->type == cm_subshell)
  169. optimize_subshell_command (command->value.Subshell->command);
  170. --- 1665,1670 ----
  171. and set CMD_TRY_OPTIMIZING for simple commands on the right side of an
  172. and-or or `;' list to test for optimizing forks when they are executed. */
  173. ! if (user_subshell && command->type == cm_subshell &&
  174. ! (command->flags & (CMD_TIME_PIPELINE|CMD_INVERT_RETURN)) == 0)
  175. optimize_subshell_command (command->value.Subshell->command);
  176. *** ../bash-5.2/patchlevel.h 2020-06-22 14:51:03.000000000 -0400
  177. --- patchlevel.h 2020-10-01 11:01:28.000000000 -0400
  178. ***************
  179. *** 26,30 ****
  180. looks for to find the patch level (for the sccs version string). */
  181. ! #define PATCHLEVEL 14
  182. #endif /* _PATCHLEVEL_H_ */
  183. --- 26,30 ----
  184. looks for to find the patch level (for the sccs version string). */
  185. ! #define PATCHLEVEL 15
  186. #endif /* _PATCHLEVEL_H_ */