From 5093e67c9240bd0f821658bbe2830cad267ed5cb Mon Sep 17 00:00:00 2001 From: yanglongkang Date: Tue, 28 Oct 2025 10:35:45 +0800 Subject: [PATCH] sync patches from bash community --- ...7-fix-for-optimizing-forks-when-usin.patch | 26 +++ ...9-fix-case-where-background-job-set-.patch | 41 ++++ ...0-allow-time-reserved-word-as-first-.patch | 38 ++++ ...1-fix-for-expanding-command-substitu.patch | 35 ++++ ...2-fix-readline-attempting-to-zero-ou.patch | 31 +++ ...3-fix-local-from-overwriting-saved-s.patch | 41 ++++ ...4-fix-problem-with-tilde-expansion-o.patch | 61 ++++++ ...5-fix-problem-with-subshells-termina.patch | 27 +++ ...h-27-fix-autoconf-test-for-strtoimax.patch | 39 ++++ ...8-fix-terminal-pgrp-handling-in-DEBU.patch | 27 +++ ...9-fix-for-error-recovery-when-parsin.patch | 92 +++++++++ ...0-fix-bug-with-marking-jobs-terminat.patch | 94 +++++++++ ...1-fix-memory-leak-in-optimized-file-.patch | 27 +++ ...2-fix-printing-coprocs-when-the-copr.patch | 28 +++ ...4-fix-for-parsing-compound-assignmen.patch | 106 +++++++++++ ...6-fix-for-reading-partial-invalid-mu.patch | 180 ++++++++++++++++++ ...tra-copy-of-function-bodies-fix-some.patch | 72 +++++++ ...-uncovered-by-address-sanitizer-work.patch | 46 +++++ bash.spec | 23 ++- 19 files changed, 1033 insertions(+), 1 deletion(-) create mode 100644 backport-Bash-5.2-patch-17-fix-for-optimizing-forks-when-usin.patch create mode 100644 backport-Bash-5.2-patch-19-fix-case-where-background-job-set-.patch create mode 100644 backport-Bash-5.2-patch-20-allow-time-reserved-word-as-first-.patch create mode 100644 backport-Bash-5.2-patch-21-fix-for-expanding-command-substitu.patch create mode 100644 backport-Bash-5.2-patch-22-fix-readline-attempting-to-zero-ou.patch create mode 100644 backport-Bash-5.2-patch-23-fix-local-from-overwriting-saved-s.patch create mode 100644 backport-Bash-5.2-patch-24-fix-problem-with-tilde-expansion-o.patch create mode 100644 backport-Bash-5.2-patch-25-fix-problem-with-subshells-termina.patch create mode 100644 backport-Bash-5.2-patch-27-fix-autoconf-test-for-strtoimax.patch create mode 100644 backport-Bash-5.2-patch-28-fix-terminal-pgrp-handling-in-DEBU.patch create mode 100644 backport-Bash-5.2-patch-29-fix-for-error-recovery-when-parsin.patch create mode 100644 backport-Bash-5.2-patch-30-fix-bug-with-marking-jobs-terminat.patch create mode 100644 backport-Bash-5.2-patch-31-fix-memory-leak-in-optimized-file-.patch create mode 100644 backport-Bash-5.2-patch-32-fix-printing-coprocs-when-the-copr.patch create mode 100644 backport-Bash-5.2-patch-34-fix-for-parsing-compound-assignmen.patch create mode 100644 backport-Bash-5.2-patch-36-fix-for-reading-partial-invalid-mu.patch create mode 100644 backport-avoid-storing-extra-copy-of-function-bodies-fix-some.patch create mode 100644 backport-fix-minor-errors-uncovered-by-address-sanitizer-work.patch diff --git a/backport-Bash-5.2-patch-17-fix-for-optimizing-forks-when-usin.patch b/backport-Bash-5.2-patch-17-fix-for-optimizing-forks-when-usin.patch new file mode 100644 index 0000000..d33a8cc --- /dev/null +++ b/backport-Bash-5.2-patch-17-fix-for-optimizing-forks-when-usin.patch @@ -0,0 +1,26 @@ +From 7d7979ba4c2b7848b81f526eac44340909ddd5a1 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 9 Nov 2023 16:44:13 -0500 +Subject: [PATCH] Bash-5.2 patch 17: fix for optimizing forks when using the . + builtin in a subshell + +--- + builtins/evalfile.c | 2 +- + 1 file changed, 1 insertions(+), 1 deletions(-) + +diff --git a/builtins/evalfile.c b/builtins/evalfile.c +index fc3975ec..604de577 100644 +--- a/builtins/evalfile.c ++++ b/builtins/evalfile.c +@@ -266,7 +266,7 @@ file_error_and_exit: + #endif + + /* set the flags to be passed to parse_and_execute */ +- pflags = SEVAL_RESETLINE; ++ pflags = SEVAL_RESETLINE|SEVAL_NOOPTIMIZE; + pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST; + + if (flags & FEVAL_BUILTIN) +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-19-fix-case-where-background-job-set-.patch b/backport-Bash-5.2-patch-19-fix-case-where-background-job-set-.patch new file mode 100644 index 0000000..aeb83eb --- /dev/null +++ b/backport-Bash-5.2-patch-19-fix-case-where-background-job-set-.patch @@ -0,0 +1,41 @@ +From f4cb298c0226a530ffd4bdc83763e848499370f8 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 9 Nov 2023 16:45:56 -0500 +Subject: [PATCH] Bash-5.2 patch 19: fix case where background job set the + terminal process group + +--- + jobs.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/jobs.c b/jobs.c +index 45869dd8..b96230fa 100644 +--- a/jobs.c ++++ b/jobs.c +@@ -3099,9 +3099,13 @@ if (job == NO_JOB) + /* Don't modify terminal pgrp if we are running in background or a + subshell. Make sure subst.c:command_substitute uses the same + conditions to determine whether or not it should undo this and +- give the terminal to pipeline_pgrp. */ +- ++ give the terminal to pipeline_pgrp. We don't give the terminal ++ back to shell_pgrp if an async job in the background exits because ++ we never gave it to that job in the first place. An async job in ++ the foreground is one we started in the background and foregrounded ++ with `fg', and gave it the terminal. */ + if ((flags & JWAIT_NOTERM) == 0 && running_in_background == 0 && ++ (job == NO_JOB || IS_ASYNC (job) == 0 || IS_FOREGROUND (job)) && + (subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0) + give_terminal_to (shell_pgrp, 0); + } +@@ -3645,6 +3649,7 @@ start_job (job, foreground) + { + get_tty_state (); + save_stty = shell_tty_info; ++ jobs[job]->flags &= ~J_ASYNC; /* no longer async */ + /* Give the terminal to this job. */ + if (IS_JOBCONTROL (job)) + give_terminal_to (jobs[job]->pgrp, 0); +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-20-allow-time-reserved-word-as-first-.patch b/backport-Bash-5.2-patch-20-allow-time-reserved-word-as-first-.patch new file mode 100644 index 0000000..eee1f01 --- /dev/null +++ b/backport-Bash-5.2-patch-20-allow-time-reserved-word-as-first-.patch @@ -0,0 +1,38 @@ +From b8a52e05d4319c6103e7e056a2bd2ae53e5fef47 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 9 Nov 2023 16:46:47 -0500 +Subject: [PATCH] Bash-5.2 patch 20: allow time reserved word as first token in + command substitution + +--- + parse.y | 1 + + y.tab.c | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/parse.y b/parse.y +index b360dd7d..8fd24a1c 100644 +--- a/parse.y ++++ b/parse.y +@@ -3135,6 +3135,7 @@ time_command_acceptable () + case TIME: /* time time pipeline */ + case TIMEOPT: /* time -p time pipeline */ + case TIMEIGN: /* time -p -- ... */ ++ case DOLPAREN: + return 1; + default: + return 0; +diff --git a/y.tab.c b/y.tab.c +index a24e3f42..78c79306 100644 +--- a/y.tab.c ++++ b/y.tab.c +@@ -5446,6 +5446,7 @@ time_command_acceptable () + case TIME: /* time time pipeline */ + case TIMEOPT: /* time -p time pipeline */ + case TIMEIGN: /* time -p -- ... */ ++ case DOLPAREN: + return 1; + default: + return 0; +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-21-fix-for-expanding-command-substitu.patch b/backport-Bash-5.2-patch-21-fix-for-expanding-command-substitu.patch new file mode 100644 index 0000000..e9df1a5 --- /dev/null +++ b/backport-Bash-5.2-patch-21-fix-for-expanding-command-substitu.patch @@ -0,0 +1,35 @@ +From 2bb3cbefdb8fd019765b1a9cc42ecf37ff22fec6 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 9 Nov 2023 16:48:34 -0500 +Subject: [PATCH] Bash-5.2 patch 21: fix for expanding command substitutions in + a word expansion in a here-document + +--- + subst.c | 4 ++-- + 1 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/subst.c b/subst.c +index 1ac6eb2d..0dfabfea 100644 +--- a/subst.c ++++ b/subst.c +@@ -1693,7 +1693,7 @@ extract_heredoc_dolbrace_string (string, sindex, quoted, flags) + t = extract_command_subst (string, &si, flags); + CHECK_STRING_OVERRUN (i, si, slen, c); + +- tlen = si - i - 1; ++ tlen = si - i - 2; + RESIZE_MALLOCED_BUFFER (result, result_index, tlen + 4, result_size, 64); + result[result_index++] = c; + result[result_index++] = LPAREN; +@@ -1713,7 +1713,7 @@ extract_heredoc_dolbrace_string (string, sindex, quoted, flags) + t = extract_process_subst (string, (string[i] == '<' ? "<(" : ">)"), &si, flags); + CHECK_STRING_OVERRUN (i, si, slen, c); + +- tlen = si - i - 1; ++ tlen = si - i - 2; + RESIZE_MALLOCED_BUFFER (result, result_index, tlen + 4, result_size, 64); + result[result_index++] = c; + result[result_index++] = LPAREN; +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-22-fix-readline-attempting-to-zero-ou.patch b/backport-Bash-5.2-patch-22-fix-readline-attempting-to-zero-ou.patch new file mode 100644 index 0000000..df8d634 --- /dev/null +++ b/backport-Bash-5.2-patch-22-fix-readline-attempting-to-zero-ou.patch @@ -0,0 +1,31 @@ +From 1a2f3d51391de5329650b4f8f62eebb0def25858 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Sat, 13 Jan 2024 18:19:59 -0500 +Subject: [PATCH] Bash-5.2 patch 22: fix readline attempting to zero out a line + that is not null-terminated + +--- + lib/readline/display.c | 7 ++----- + 1 file changed, 2 insertions(+), 5 deletions(-) + +diff --git a/lib/readline/display.c b/lib/readline/display.c +index c1135ec5..ad573f9a 100644 +--- a/lib/readline/display.c ++++ b/lib/readline/display.c +@@ -2683,11 +2683,8 @@ rl_forced_update_display (void) + register char *temp; + + if (visible_line) +- { +- temp = visible_line; +- while (*temp) +- *temp++ = '\0'; +- } ++ memset (visible_line, 0, line_size); ++ + rl_on_new_line (); + forced_display++; + (*rl_redisplay_function) (); +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-23-fix-local-from-overwriting-saved-s.patch b/backport-Bash-5.2-patch-23-fix-local-from-overwriting-saved-s.patch new file mode 100644 index 0000000..ab2b25a --- /dev/null +++ b/backport-Bash-5.2-patch-23-fix-local-from-overwriting-saved-s.patch @@ -0,0 +1,41 @@ +From c22ce0d04a9097effb7d1245406cbcdcfa82a1cb Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Sat, 13 Jan 2024 18:20:47 -0500 +Subject: [PATCH] Bash-5.2 patch 23: fix local - from overwriting saved set of + options + +--- + builtins/declare.def | 16 ++++++++++++---- + 1 file1 changed, 12 insertions(+), 4 deletions(-) + +diff --git a/builtins/declare.def b/builtins/declare.def +index 54db59c5..7a1b60c8 100644 +--- a/builtins/declare.def ++++ b/builtins/declare.def +@@ -420,11 +420,19 @@ declare_internal (list, local_var) + + if (local_var && variable_context && STREQ (name, "-")) + { ++ int o; ++ ++ o = localvar_inherit; ++ localvar_inherit = 0; + var = make_local_variable ("-", 0); +- FREE (value_cell (var)); /* just in case */ +- value = get_current_options (); +- var_setvalue (var, value); +- VSETATTR (var, att_invisible); ++ localvar_inherit = o; ++ ++ if (value_cell (var) == NULL) /* no duplicate instances */ ++ { ++ value = get_current_options (); ++ var_setvalue (var, value); ++ VSETATTR (var, att_invisible); ++ } + NEXT_VARIABLE (); + } + +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-24-fix-problem-with-tilde-expansion-o.patch b/backport-Bash-5.2-patch-24-fix-problem-with-tilde-expansion-o.patch new file mode 100644 index 0000000..dd6fb96 --- /dev/null +++ b/backport-Bash-5.2-patch-24-fix-problem-with-tilde-expansion-o.patch @@ -0,0 +1,61 @@ +From d1cf6ad908f986765d2acc48095a2f6cea0a874d Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Sat, 13 Jan 2024 18:24:10 -0500 +Subject: [PATCH] Bash-5.2 patch 24: fix problem with tilde expansion of values + in compound associative array assignments + +--- + arrayfunc.c | 6 +++--- + subst.c | 4 ++++ + 2 files changed, 7 insertions(+), 3 deletions(-) + +diff --git a/arrayfunc.c b/arrayfunc.c +index 2c05d15b..41256227 100644 +--- a/arrayfunc.c ++++ b/arrayfunc.c +@@ -650,7 +650,7 @@ assign_assoc_from_kvlist (var, nlist, h, flags) + continue; + } + +- aval = expand_subscript_string (v, 0); ++ aval = expand_assignment_string_to_string (v, 0); + if (aval == 0) + { + aval = (char *)xmalloc (1); +@@ -842,7 +842,7 @@ assign_compound_array_list (var, nlist, flags) + /* See above; we need to expand the value here */ + if (assoc_p (var)) + { +- val = expand_subscript_string (val, 0); ++ val = expand_assignment_string_to_string (val, 0); + if (val == 0) + { + val = (char *)xmalloc (1); +@@ -1030,7 +1030,7 @@ expand_and_quote_assoc_word (w, type) + nword[i++] = w[ind++]; + nword[i++] = w[ind++]; + +- t = expand_subscript_string (w+ind, 0); ++ t = expand_assignment_string_to_string (w+ind, 0); + s = (t && strchr (t, CTLESC)) ? quote_escapes (t) : t; + value = sh_single_quote (s ? s : ""); + if (s != t) +diff --git a/subst.c b/subst.c +index 0dfabfea..2012e1fd 100644 +--- a/subst.c ++++ b/subst.c +@@ -10802,7 +10802,11 @@ expand_subscript_string (string, quoted) + oe = expand_no_split_dollar_star; + ret = (char *)NULL; + ++#if 0 + td.flags = W_NOPROCSUB|W_NOTILDE|W_NOSPLIT2; /* XXX - W_NOCOMSUB? */ ++#else ++ td.flags = W_NOPROCSUB|W_NOSPLIT2; /* XXX - W_NOCOMSUB? */ ++#endif + td.word = savestring (string); /* in case it's freed on error */ + + expand_no_split_dollar_star = 1; +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-25-fix-problem-with-subshells-termina.patch b/backport-Bash-5.2-patch-25-fix-problem-with-subshells-termina.patch new file mode 100644 index 0000000..de83438 --- /dev/null +++ b/backport-Bash-5.2-patch-25-fix-problem-with-subshells-termina.patch @@ -0,0 +1,27 @@ +From 0bec38a566a4dcbdb44e04b4f2ae310ac47e7ef6 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Sat, 13 Jan 2024 18:26:00 -0500 +Subject: [PATCH] Bash-5.2 patch 25: fix problem with subshells terminated by a + signal exiting with the wrong status + +--- + execute_cmd.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/execute_cmd.c b/execute_cmd.c +index f2e3cf32..ed1063e6 100644 +--- a/execute_cmd.c ++++ b/execute_cmd.c +@@ -1725,6 +1725,9 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close) + return_code = (return_code == EXECUTION_SUCCESS) ? EXECUTION_FAILURE + : EXECUTION_SUCCESS; + ++ /* Check for terminating signals before we return to our caller, which we ++ expect to exit immediately anyway. */ ++ CHECK_TERMSIG; + + /* If we were explicitly placed in a subshell with (), we need + to do the `shell cleanup' things, such as running traps[0]. */ +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-27-fix-autoconf-test-for-strtoimax.patch b/backport-Bash-5.2-patch-27-fix-autoconf-test-for-strtoimax.patch new file mode 100644 index 0000000..b770eb7 --- /dev/null +++ b/backport-Bash-5.2-patch-27-fix-autoconf-test-for-strtoimax.patch @@ -0,0 +1,39 @@ +From da16dd1e74ddb8ff44d15f720c52be582b77fff4 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 1 Aug 2024 11:31:51 -0400 +Subject: [PATCH] Bash-5.2 patch 27: fix autoconf test for strtoimax + +--- + configure | 2 +- + m4/strtoimax.m4 | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/configure b/configure +index 47313753..07d7c2f6 100755 +--- a/configure ++++ b/configure +@@ -20443,7 +20443,7 @@ fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $bash_cv_func_strtoimax" >&5 + printf "%s\n" "$bash_cv_func_strtoimax" >&6; } +-if test $bash_cv_func_strtoimax = yes; then ++if test $bash_cv_func_strtoimax = no; then + case " $LIBOBJS " in + *" strtoimax.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strtoimax.$ac_objext" +diff --git a/m4/strtoimax.m4 b/m4/strtoimax.m4 +index 30985723..d311c9d0 100644 +--- a/m4/strtoimax.m4 ++++ b/m4/strtoimax.m4 +@@ -29,7 +29,7 @@ AC_CACHE_VAL(bash_cv_func_strtoimax, + fi + ]) + AC_MSG_RESULT($bash_cv_func_strtoimax) +-if test $bash_cv_func_strtoimax = yes; then ++if test $bash_cv_func_strtoimax = no; then + AC_LIBOBJ(strtoimax) + fi + ]) +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-28-fix-terminal-pgrp-handling-in-DEBU.patch b/backport-Bash-5.2-patch-28-fix-terminal-pgrp-handling-in-DEBU.patch new file mode 100644 index 0000000..1c59e8b --- /dev/null +++ b/backport-Bash-5.2-patch-28-fix-terminal-pgrp-handling-in-DEBU.patch @@ -0,0 +1,27 @@ +From 7440bd8ba5a6e542cc59754a15871c5a42cdeae9 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 1 Aug 2024 11:33:15 -0400 +Subject: [PATCH] Bash-5.2 patch 28: fix terminal pgrp handling in DEBUG trap + +--- + trap.c | 4 +++- + 1 files changed, 3 insertions(+), 1 deletions(-) + +diff --git a/trap.c b/trap.c +index e56f6cc3..465c3360 100644 +--- a/trap.c ++++ b/trap.c +@@ -1216,7 +1216,9 @@ run_debug_trap () + close_pgrp_pipe (); + restore_pgrp_pipe (save_pipe); + # endif +- if (pipeline_pgrp > 0 && ((subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0)) ++ /* If the trap command gave the terminal to another process group, ++ restore it. XXX - check running_in_background? */ ++ if (job_control && pipeline_pgrp > 0 && ((subshell_environment & (SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0)) + give_terminal_to (pipeline_pgrp, 1); + + notify_and_cleanup (); +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-29-fix-for-error-recovery-when-parsin.patch b/backport-Bash-5.2-patch-29-fix-for-error-recovery-when-parsin.patch new file mode 100644 index 0000000..20dc927 --- /dev/null +++ b/backport-Bash-5.2-patch-29-fix-for-error-recovery-when-parsin.patch @@ -0,0 +1,92 @@ +From bc3e91dbec5d985b41b229f9b7cc9572ae624922 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 1 Aug 2024 11:34:42 -0400 +Subject: [PATCH] Bash-5.2 patch 29: fix for error recovery when parsing + invalid compound assignments + +--- + parse.y | 15 ++++++++++++--- + y.tab.c | 15 ++++++++++++--- + 2 files changed, 24 insertions(+), 6 deletions(-) + +diff --git a/parse.y b/parse.y +index 8fd24a1c..78b49175 100644 +--- a/parse.y ++++ b/parse.y +@@ -6470,10 +6470,15 @@ parse_string_to_word_list (s, flags, whom) + if (wl == &parse_string_error) + { + set_exit_status (EXECUTION_FAILURE); ++ current_token = '\n'; /* XXX */ + if (interactive_shell == 0 && posixly_correct) + jump_to_top_level (FORCE_EOF); + else +- jump_to_top_level (DISCARD); ++ { ++ if (executing && parse_and_execute_level == 0) ++ top_level_cleanup (); ++ jump_to_top_level (DISCARD); ++ } + } + + return (REVERSE_LIST (wl, WORD_LIST *)); +@@ -6537,11 +6542,15 @@ parse_compound_assignment (retlenp) + if (wl == &parse_string_error) + { + set_exit_status (EXECUTION_FAILURE); +- last_read_token = '\n'; /* XXX */ ++ last_read_token = current_token = '\n'; /* XXX */ + if (interactive_shell == 0 && posixly_correct) + jump_to_top_level (FORCE_EOF); + else +- jump_to_top_level (DISCARD); ++ { ++ if (executing && parse_and_execute_level == 0) ++ top_level_cleanup (); ++ jump_to_top_level (DISCARD); ++ } + } + + if (wl) +diff --git a/y.tab.c b/y.tab.c +index 78c79306..793686e7 100644 +--- a/y.tab.c ++++ b/y.tab.c +@@ -8785,10 +8785,15 @@ parse_string_to_word_list (s, flags, whom) + if (wl == &parse_string_error) + { + set_exit_status (EXECUTION_FAILURE); ++ current_token = '\n'; /* XXX */ + if (interactive_shell == 0 && posixly_correct) + jump_to_top_level (FORCE_EOF); + else +- jump_to_top_level (DISCARD); ++ { ++ if (executing && parse_and_execute_level == 0) ++ top_level_cleanup (); ++ jump_to_top_level (DISCARD); ++ } + } + + return (REVERSE_LIST (wl, WORD_LIST *)); +@@ -8852,11 +8857,15 @@ parse_compound_assignment (retlenp) + if (wl == &parse_string_error) + { + set_exit_status (EXECUTION_FAILURE); +- last_read_token = '\n'; /* XXX */ ++ last_read_token = current_token = '\n'; /* XXX */ + if (interactive_shell == 0 && posixly_correct) + jump_to_top_level (FORCE_EOF); + else +- jump_to_top_level (DISCARD); ++ { ++ if (executing && parse_and_execute_level == 0) ++ top_level_cleanup (); ++ jump_to_top_level (DISCARD); ++ } + } + + if (wl) +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-30-fix-bug-with-marking-jobs-terminat.patch b/backport-Bash-5.2-patch-30-fix-bug-with-marking-jobs-terminat.patch new file mode 100644 index 0000000..b7f7e04 --- /dev/null +++ b/backport-Bash-5.2-patch-30-fix-bug-with-marking-jobs-terminat.patch @@ -0,0 +1,94 @@ +From 6e45e752d6749e2fb5c267b388f4c450f4b13f95 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 1 Aug 2024 11:36:07 -0400 +Subject: [PATCH] Bash-5.2 patch 30: fix bug with marking jobs terminated by + signals as notified + +--- + jobs.c | 40 ++++++++++++++++++++++++++++++++++++---- + 1 file changed, 36 insertions(+), 4 deletions(-) + +diff --git a/jobs.c b/jobs.c +index b96230fa..d3e4ab05 100644 +--- a/jobs.c ++++ b/jobs.c +@@ -4274,7 +4274,27 @@ notify_of_job_status () + if (startup_state == 0 && WIFSIGNALED (s) == 0 && + ((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job))) + continue; +- ++ ++ /* Do the same thing and don't print anything or mark as notified ++ for the signals we're not going to report on. This is the opposite ++ of the first two cases under case JDEAD below. */ ++ else if (interactive_shell == 0 && DEADJOB (job) && IS_FOREGROUND (job) == 0 && ++ WIFSIGNALED (s) && (termsig == SIGINT ++#if defined (DONT_REPORT_SIGTERM) ++ || termsig == SIGTERM ++#endif ++#if defined (DONT_REPORT_SIGPIPE) ++ || termsig == SIGPIPE ++#endif ++ || signal_is_trapped (termsig))) ++ continue; ++ ++ /* hang onto the status if the shell is running -c command */ ++ else if (startup_state == 2 && subshell_environment == 0 && ++ WIFSIGNALED (s) == 0 && ++ ((DEADJOB (job) && IS_FOREGROUND (job) == 0) || STOPPED (job))) ++ continue; ++ + /* If job control is disabled, don't print the status messages. + Mark dead jobs as notified so that they get cleaned up. If + startup_state == 2 and subshell_environment has the +@@ -4297,7 +4317,7 @@ notify_of_job_status () + + /* Print info on jobs that are running in the background, + and on foreground jobs that were killed by anything +- except SIGINT (and possibly SIGPIPE). */ ++ except SIGINT (and possibly SIGTERM and SIGPIPE). */ + switch (JOBSTATE (job)) + { + case JDEAD: +@@ -4317,6 +4337,7 @@ notify_of_job_status () + } + else if (IS_FOREGROUND (job)) + { ++ /* foreground jobs, interactive and non-interactive shells */ + #if !defined (DONT_REPORT_SIGPIPE) + if (termsig && WIFSIGNALED (s) && termsig != SIGINT) + #else +@@ -4330,9 +4351,13 @@ notify_of_job_status () + + fprintf (stderr, "\n"); + } ++ /* foreground jobs that exit cleanly */ ++ jobs[job]->flags |= J_NOTIFIED; + } +- else if (job_control) /* XXX job control test added */ ++ else if (job_control) + { ++ /* background jobs with job control, interactive and ++ non-interactive shells */ + if (dir == 0) + dir = current_working_directory (); + pretty_print_job (job, JLIST_STANDARD, stderr); +@@ -4341,7 +4366,14 @@ notify_of_job_status () + _("(wd now: %s)\n"), polite_directory_format (dir)); + } + +- jobs[job]->flags |= J_NOTIFIED; ++ /* Interactive shells without job control enabled are handled ++ above. */ ++ /* XXX - this is a catch-all in case we missed a state */ ++ else ++{ ++internal_debug("notify_of_job_status: catch-all setting J_NOTIFIED on job %d (%d), startup state = %d", job, jobs[job]->flags, startup_state); ++ jobs[job]->flags |= J_NOTIFIED; ++} + break; + + case JSTOPPED: +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-31-fix-memory-leak-in-optimized-file-.patch b/backport-Bash-5.2-patch-31-fix-memory-leak-in-optimized-file-.patch new file mode 100644 index 0000000..3fa33f3 --- /dev/null +++ b/backport-Bash-5.2-patch-31-fix-memory-leak-in-optimized-file-.patch @@ -0,0 +1,27 @@ +From 471fd9a3f0dc1fb4694cef6429c60ef1c993e077 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Thu, 1 Aug 2024 11:37:23 -0400 +Subject: [PATCH] Bash-5.2 patch 31: fix memory leak in optimized $( +Date: Thu, 1 Aug 2024 11:38:37 -0400 +Subject: [PATCH] Bash-5.2 patch 32: fix printing coprocs when the coproc does + not have a name + +--- + print_cmd.c | 4 +++- + 1 files changed, 3 insertions(+), 1 deletions(-) + +diff --git a/print_cmd.c b/print_cmd.c +index b8154947..a16c2486 100644 +--- a/print_cmd.c ++++ b/print_cmd.c +@@ -356,7 +356,9 @@ make_command_string_internal (command) + break; + + case cm_coproc: +- cprintf ("coproc %s ", command->value.Coproc->name); ++ cprintf ("coproc "); ++ if (command->value.Coproc->command->type != cm_simple) ++ cprintf ("%s ", command->value.Coproc->name); + skip_this_indent++; + make_command_string_internal (command->value.Coproc->command); + break; +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-34-fix-for-parsing-compound-assignmen.patch b/backport-Bash-5.2-patch-34-fix-for-parsing-compound-assignmen.patch new file mode 100644 index 0000000..4861ad6 --- /dev/null +++ b/backport-Bash-5.2-patch-34-fix-for-parsing-compound-assignmen.patch @@ -0,0 +1,106 @@ +From 2abedfbddbb12f2f71da2677f9567ea9cafdeeb5 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Mon, 23 Sep 2024 18:14:07 -0400 +Subject: [PATCH] Bash-5.2 patch 34: fix for parsing compound assignment while + expanding alias + +--- + parse.y | 18 +- + y.tab.c | 18 +- + 2 files changed, 34 insertions(+), 2 deletions(-) + +diff --git a/parse.y b/parse.y +index 78b49175..e4b3b8ed 100644 +--- a/parse.y ++++ b/parse.y +@@ -6489,9 +6489,10 @@ parse_compound_assignment (retlenp) + int *retlenp; + { + WORD_LIST *wl, *rl; +- int tok, orig_line_number, assignok; ++ int tok, orig_line_number, assignok, ea, restore_pushed_strings; + sh_parser_state_t ps; + char *ret; ++ STRING_SAVER *ss; + + orig_line_number = line_number; + save_parser_state (&ps); +@@ -6514,6 +6515,12 @@ parse_compound_assignment (retlenp) + + esacs_needed_count = expecting_in_token = 0; + ++ /* We're not pushing any new input here, we're reading from the current input ++ source. If that's an alias, we have to be prepared for the alias to get ++ popped out from underneath us. */ ++ ss = (ea = expanding_alias ()) ? pushed_string_list : (STRING_SAVER *)NULL; ++ restore_pushed_strings = 0; ++ + while ((tok = read_token (READ)) != ')') + { + if (tok == '\n') /* Allow newlines in compound assignments */ +@@ -6537,7 +6544,16 @@ parse_compound_assignment (retlenp) + wl = make_word_list (yylval.word, wl); + } + ++ /* Check whether or not an alias got popped out from underneath us and ++ fix up after restore_parser_state. */ ++ if (ea && ss && ss != pushed_string_list) ++ { ++ restore_pushed_strings = 1; ++ ss = pushed_string_list; ++ } + restore_parser_state (&ps); ++ if (restore_pushed_strings) ++ pushed_string_list = ss; + + if (wl == &parse_string_error) + { +diff --git a/y.tab.c b/y.tab.c +index 793686e7..e97549a9 100644 +--- a/y.tab.c ++++ b/y.tab.c +@@ -8804,9 +8804,10 @@ parse_compound_assignment (retlenp) + int *retlenp; + { + WORD_LIST *wl, *rl; +- int tok, orig_line_number, assignok; ++ int tok, orig_line_number, assignok, ea, restore_pushed_strings; + sh_parser_state_t ps; + char *ret; ++ STRING_SAVER *ss; + + orig_line_number = line_number; + save_parser_state (&ps); +@@ -8829,6 +8830,12 @@ parse_compound_assignment (retlenp) + + esacs_needed_count = expecting_in_token = 0; + ++ /* We're not pushing any new input here, we're reading from the current input ++ source. If that's an alias, we have to be prepared for the alias to get ++ popped out from underneath us. */ ++ ss = (ea = expanding_alias ()) ? pushed_string_list : (STRING_SAVER *)NULL; ++ restore_pushed_strings = 0; ++ + while ((tok = read_token (READ)) != ')') + { + if (tok == '\n') /* Allow newlines in compound assignments */ +@@ -8852,7 +8859,16 @@ parse_compound_assignment (retlenp) + wl = make_word_list (yylval.word, wl); + } + ++ /* Check whether or not an alias got popped out from underneath us and ++ fix up after restore_parser_state. */ ++ if (ea && ss && ss != pushed_string_list) ++ { ++ restore_pushed_strings = 1; ++ ss = pushed_string_list; ++ } + restore_parser_state (&ps); ++ if (restore_pushed_strings) ++ pushed_string_list = ss; + + if (wl == &parse_string_error) + { +-- +2.43.0 + diff --git a/backport-Bash-5.2-patch-36-fix-for-reading-partial-invalid-mu.patch b/backport-Bash-5.2-patch-36-fix-for-reading-partial-invalid-mu.patch new file mode 100644 index 0000000..9be5e6a --- /dev/null +++ b/backport-Bash-5.2-patch-36-fix-for-reading-partial-invalid-mu.patch @@ -0,0 +1,180 @@ +From fda8d33282f61d337c760fc828def82d66e9ff0d Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Mon, 23 Sep 2024 18:17:46 -0400 +Subject: [PATCH] Bash-5.2 patch 36: fix for reading partial invalid multibyte + characters + +--- + lib/readline/text.c | 67 +++++++++++++++++++++++++++++++++++++-------- + 1 files changed, 55 insertions(+), 12 deletions(-) + +diff --git a/lib/readline/text.c b/lib/readline/text.c +index 91c3f330..8f092f58 100644 +--- a/lib/readline/text.c ++++ b/lib/readline/text.c +@@ -85,7 +85,8 @@ int _rl_optimize_typeahead = 1; /* rl_insert tries to read typeahead */ + int + rl_insert_text (const char *string) + { +- register int i, l; ++ register int i; ++ size_t l; + + l = (string && *string) ? strlen (string) : 0; + if (l == 0) +@@ -704,7 +705,11 @@ static mbstate_t ps = {0}; + + /* Insert the character C at the current location, moving point forward. + If C introduces a multibyte sequence, we read the whole sequence and +- then insert the multibyte char into the line buffer. */ ++ then insert the multibyte char into the line buffer. ++ If C == 0, we immediately insert any pending partial multibyte character, ++ assuming that we have read a character that doesn't map to self-insert. ++ This doesn't completely handle characters that are part of a multibyte ++ character but map to editing functions. */ + int + _rl_insert_char (int count, int c) + { +@@ -718,11 +723,28 @@ _rl_insert_char (int count, int c) + static int stored_count = 0; + #endif + ++#if !defined (HANDLE_MULTIBYTE) + if (count <= 0) + return 0; ++#else ++ if (count < 0) ++ return 0; ++ if (count == 0) ++ { ++ if (pending_bytes_length == 0) ++ return 0; ++ if (stored_count <= 0) ++ stored_count = count; ++ else ++ count = stored_count; + +-#if defined (HANDLE_MULTIBYTE) +- if (MB_CUR_MAX == 1 || rl_byte_oriented) ++ memcpy (incoming, pending_bytes, pending_bytes_length); ++ incoming[pending_bytes_length] = '\0'; ++ incoming_length = pending_bytes_length; ++ pending_bytes_length = 0; ++ memset (&ps, 0, sizeof (mbstate_t)); ++ } ++ else if (MB_CUR_MAX == 1 || rl_byte_oriented) + { + incoming[0] = c; + incoming[1] = '\0'; +@@ -730,6 +752,9 @@ _rl_insert_char (int count, int c) + } + else if (_rl_utf8locale && (c & 0x80) == 0) + { ++ if (pending_bytes_length) ++ _rl_insert_char (0, 0); ++ + incoming[0] = c; + incoming[1] = '\0'; + incoming_length = 1; +@@ -764,7 +789,8 @@ _rl_insert_char (int count, int c) + incoming[1] = '\0'; + incoming_length = 1; + pending_bytes_length--; +- memmove (pending_bytes, pending_bytes + 1, pending_bytes_length); ++ if (pending_bytes_length) ++ memmove (pending_bytes, pending_bytes + 1, pending_bytes_length); + /* Clear the state of the byte sequence, because in this case the + effect of mbstate is undefined. */ + memset (&ps, 0, sizeof (mbstate_t)); +@@ -827,7 +853,11 @@ _rl_insert_char (int count, int c) + rl_insert_text (string); + xfree (string); + ++#if defined (HANDLE_MULTIBYTE) ++ return (pending_bytes_length != 0); ++#else + return 0; ++#endif + } + + if (count > TEXT_COUNT_MAX) +@@ -860,6 +890,8 @@ _rl_insert_char (int count, int c) + xfree (string); + incoming_length = 0; + stored_count = 0; ++ ++ return (pending_bytes_length != 0); + #else /* !HANDLE_MULTIBYTE */ + char str[TEXT_COUNT_MAX+1]; + +@@ -873,9 +905,9 @@ _rl_insert_char (int count, int c) + rl_insert_text (str); + count -= decreaser; + } +-#endif /* !HANDLE_MULTIBYTE */ + + return 0; ++#endif /* !HANDLE_MULTIBYTE */ + } + + if (MB_CUR_MAX == 1 || rl_byte_oriented) +@@ -903,9 +935,11 @@ _rl_insert_char (int count, int c) + rl_insert_text (incoming); + stored_count = 0; + } +-#endif +- ++ ++ return (pending_bytes_length != 0); ++#else + return 0; ++#endif + } + + /* Overwrite the character at point (or next COUNT characters) with C. +@@ -983,6 +1017,11 @@ rl_insert (int count, int c) + break; + } + ++ /* If we didn't insert n and there are pending bytes, we need to insert ++ them if _rl_insert_char didn't do that on its own. */ ++ if (r == 1 && rl_insert_mode == RL_IM_INSERT) ++ r = _rl_insert_char (0, 0); /* flush partial multibyte char */ ++ + if (n != (unsigned short)-2) /* -2 = sentinel value for having inserted N */ + { + /* setting rl_pending_input inhibits setting rl_last_func so we do it +@@ -1054,6 +1093,8 @@ _rl_insert_next_callback (_rl_callback_generic_arg *data) + int + rl_quoted_insert (int count, int key) + { ++ int r; ++ + /* Let's see...should the callback interface futz with signal handling? */ + #if defined (HANDLE_SIGNALS) + if (RL_ISSTATE (RL_STATE_CALLBACK) == 0) +@@ -1072,15 +1113,17 @@ rl_quoted_insert (int count, int key) + /* A negative count means to quote the next -COUNT characters. */ + if (count < 0) + { +- int r; +- + do + r = _rl_insert_next (1); + while (r == 0 && ++count < 0); +- return r; + } ++ else ++ r = _rl_insert_next (count); + +- return _rl_insert_next (count); ++ if (r == 1) ++ _rl_insert_char (0, 0); /* insert partial multibyte character */ ++ ++ return r; + } + + /* Insert a tab character. */ +-- +2.43.0 + diff --git a/backport-avoid-storing-extra-copy-of-function-bodies-fix-some.patch b/backport-avoid-storing-extra-copy-of-function-bodies-fix-some.patch new file mode 100644 index 0000000..6630cf4 --- /dev/null +++ b/backport-avoid-storing-extra-copy-of-function-bodies-fix-some.patch @@ -0,0 +1,72 @@ +From dbb48b978671394bcb33c9f34656a9aadf40a318 Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Tue, 4 Jun 2024 12:23:18 -0400 +Subject: [PATCH] avoid storing extra copy of function bodies; fix some minor + memory leaks + +--- + parse.y | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +diff --git a/parse.y b/parse.y +index 1349480b..eb83af4c 100644 +--- a/parse.y ++++ b/parse.y +@@ -1032,6 +1032,7 @@ coproc: COPROC shell_command + { + $$ = make_coproc_command ($2->word, $3); + $$->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; ++ dispose_word ($2); + } + | COPROC WORD shell_command redirection_list + { +@@ -1049,6 +1050,7 @@ coproc: COPROC shell_command + tc->redirects = $4; + $$ = make_coproc_command ($2->word, $3); + $$->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; ++ dispose_word ($2); + } + | COPROC simple_command + { +@@ -3379,14 +3381,19 @@ read_token (command) + #if defined (COND_COMMAND) + if ((parser_state & (PST_CONDCMD|PST_CONDEXPR)) == PST_CONDCMD) + { ++ COMMAND *cond_command; + cond_lineno = line_number; + parser_state |= PST_CONDEXPR; +- yylval.command = parse_cond_command (); ++ cond_command = parse_cond_command (); + if (cond_token != COND_END) + { + cond_error (); ++ if (cond_token == WORD) ++ dispose_word (yylval.word); ++ dispose_command (cond_command); + return (-1); + } ++ yylval.command = cond_command; + token_to_read = COND_END; + parser_state &= ~(PST_CONDEXPR|PST_CONDCMD); + return (COND_CMD); +@@ -4658,7 +4665,7 @@ cond_term () + else if (tok == BANG || (tok == WORD && (yylval.word->word[0] == '!' && yylval.word->word[1] == '\0'))) + { + if (tok == WORD) +- dispose_word (yylval.word); /* not needed */ ++ dispose_word (yylval.word); /* word not needed */ + term = cond_term (); + if (term) + term->flags ^= CMD_INVERT_RETURN; +@@ -4734,6 +4741,8 @@ cond_term () + else + parser_error (line_number, _("conditional binary operator expected")); + dispose_cond_node (tleft); ++ if (tok == WORD) ++ dispose_word (yylval.word); + COND_RETURN_ERROR (); + } + +-- +2.43.0 + diff --git a/backport-fix-minor-errors-uncovered-by-address-sanitizer-work.patch b/backport-fix-minor-errors-uncovered-by-address-sanitizer-work.patch new file mode 100644 index 0000000..e3a0e1b --- /dev/null +++ b/backport-fix-minor-errors-uncovered-by-address-sanitizer-work.patch @@ -0,0 +1,46 @@ +From 9cea457aef3c406893c345ade1fed7add8c536ba Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Tue, 28 May 2024 09:19:03 -0400 +Subject: [PATCH] fix minor errors uncovered by address sanitizer; work around + android issue with read -e -u; fix minor memory leaks; make + spell-correct-shellword work with negative arguments; fix readline + change-case on invalid multibyte character + +--- + bashline.c | 13 +++++++++++-- + 1 files changed, 11 insertions(+), 2 deletions(-) + +diff --git a/bashline.c b/bashline.c +index b638e001..9cdd9bc4 100644 +--- a/bashline.c ++++ b/bashline.c +@@ -2002,6 +2036,12 @@ command_word_completion_function (const char *hint_text, int state) + glob_matches = (char **)NULL; + } + ++ if (directory_part) ++ { ++ free (directory_part); ++ directory_part = (char *)NULL; ++ } ++ + globpat = completion_glob_pattern ((char *)hint_text); + + /* If this is an absolute program name, do not check it against +@@ -2425,8 +2431,11 @@ command_subst_completion_function (const char *text, int state) + rl_completion_suppress_quote = 1; + start_len = text - orig_start; + filename_text = savestring (text); +- if (matches) +- free (matches); ++ if (matches) ++ { ++ strvec_dispose (matches); ++ matches = (char **)NULL; ++ } + + /* + * At this point we can entertain the idea of re-parsing +-- +2.43.0 + diff --git a/bash.spec b/bash.spec index fe6ce43..4855107 100644 --- a/bash.spec +++ b/bash.spec @@ -2,7 +2,7 @@ Name: bash Version: 5.2.15 -Release: 18 +Release: 19 Summary: It is the Bourne Again Shell License: GPLv3 URL: https://www.gnu.org/software/bash @@ -45,6 +45,24 @@ Patch6015: backport-fourth-set-of-ANSI-C-changes-size_t-rest-globskipdot.patch Patch6016: backport-documentation-updates-fix-for-null-commands-with-red.patch Patch6017: backport-fix-for-readline-redisplay-issue-in-C-locale-fix-for.patch Patch6018: backport-fixes-for-glibc-time-gettimeofday-issue-fix-issue-wi.patch +Patch6019: backport-Bash-5.2-patch-17-fix-for-optimizing-forks-when-usin.patch +Patch6020: backport-Bash-5.2-patch-19-fix-case-where-background-job-set-.patch +Patch6021: backport-Bash-5.2-patch-20-allow-time-reserved-word-as-first-.patch +Patch6022: backport-Bash-5.2-patch-21-fix-for-expanding-command-substitu.patch +Patch6023: backport-Bash-5.2-patch-22-fix-readline-attempting-to-zero-ou.patch +Patch6024: backport-Bash-5.2-patch-23-fix-local-from-overwriting-saved-s.patch +Patch6025: backport-Bash-5.2-patch-24-fix-problem-with-tilde-expansion-o.patch +Patch6026: backport-Bash-5.2-patch-25-fix-problem-with-subshells-termina.patch +Patch6027: backport-Bash-5.2-patch-27-fix-autoconf-test-for-strtoimax.patch +Patch6028: backport-Bash-5.2-patch-28-fix-terminal-pgrp-handling-in-DEBU.patch +Patch6029: backport-Bash-5.2-patch-29-fix-for-error-recovery-when-parsin.patch +Patch6030: backport-Bash-5.2-patch-30-fix-bug-with-marking-jobs-terminat.patch +Patch6031: backport-Bash-5.2-patch-31-fix-memory-leak-in-optimized-file-.patch +Patch6032: backport-Bash-5.2-patch-32-fix-printing-coprocs-when-the-copr.patch +Patch6033: backport-Bash-5.2-patch-34-fix-for-parsing-compound-assignmen.patch +Patch6034: backport-Bash-5.2-patch-36-fix-for-reading-partial-invalid-mu.patch +Patch6035: backport-fix-minor-errors-uncovered-by-address-sanitizer-work.patch +Patch6036: backport-avoid-storing-extra-copy-of-function-bodies-fix-some.patch %if %{enable_safecheck} Patch9000: only-scripts-verified-by-execveat-are-allowed-to-run.patch @@ -177,6 +195,9 @@ make check %exclude %{_infodir}/dir %changelog +* Tue Oct 28 2025 yanglongkang - 5.2.15-19 +- sync patches from bash community + * Tue Sep 16 2025 fuanan - 5.2.15-18 - fix issue with history file containing one line too few if saving timestamps -- Gitee