From: Chet Ramey Date: Mon, 31 Mar 2025 13:58:59 +0000 (-0400) Subject: fix for multiple assignment statements containing nofork comsubs preceding a command... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6767763de5e7859107711b166a64a9e4a77a8ae;p=thirdparty%2Fbash.git fix for multiple assignment statements containing nofork comsubs preceding a command; fix for possible issue with invalid bash input fd --- diff --git a/CHANGES b/CHANGES index a264b4d2..caf1f1a6 100644 --- a/CHANGES +++ b/CHANGES @@ -35,11 +35,17 @@ j. Fixed a bug in command printing that output the wrong default file k. User-specified subshells (`(...)') now update BASH_COMMAND in the subshell. -l. Fixed a bug with the `help -m' and loadable builtins. +l. Fixed a display bug with the `help -m' and loadable builtins. m. Fixed a potential file descriptor leak when trying to use a pipe for a here document. +n. Fix a bug with multiple assignment statements preceding a simple command + containing nofork comsubs. + +o. Fix a potential bug that could result in a NULL buffered stream even with + a valid input file descriptor. + 2. Changes to Readline a. Fixed a bug that allowed a history search to change the current history diff --git a/CHANGES-5.3 b/CHANGES-5.3 index c34dfb8a..2eb4b56b 100644 --- a/CHANGES-5.3 +++ b/CHANGES-5.3 @@ -35,11 +35,17 @@ j. Fixed a bug in command printing that output the wrong default file k. User-specified subshells (`(...)') now update BASH_COMMAND in the subshell. -l. Fixed a bug with the `help -m' and loadable builtins. +l. Fixed a display bug with the `help -m' and loadable builtins. m. Fixed a potential file descriptor leak when trying to use a pipe for a here document. +n. Fix a bug with multiple assignment statements preceding a simple command + containing nofork comsubs. + +o. Fix a potential bug that could result in a NULL buffered stream even with + a valid input file descriptor. + 2. Changes to Readline a. Fixed a bug that allowed a history search to change the current history diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 9a15f86b..b0894740 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -11080,3 +11080,19 @@ configure.ac ---- lib/readline/rlmbutil.h - _rl_wcwidth: make sure wchar_t constants have an `L' prefix + + 3/24 + ---- +subst.c + - function_substitute: set temporary_env to NULL (we've already + set up an unwind-protect for it) before pushing the context, so + pop_context doesn't free it out from underneath the caller. + Report from Emanuele Torre + + 3/27 + ---- +shell.c + - set_bash_input: if the call to with_input_from_buffered_stream does + not result in a valid buffer corresponding to the file descriptor, + print an error message and set last_command_exit_value + From a report in https://savannah.gnu.org/patch/?10512 diff --git a/general.h b/general.h index 0528bbf1..c73758c2 100644 --- a/general.h +++ b/general.h @@ -213,6 +213,7 @@ typedef int sh_glist_func_t (GENERIC_LIST *); typedef int sh_gcp_func_t (GENERIC_LIST *, char *); typedef char *sh_string_func_t (char *); /* like savestring, et al. */ +typedef void *sh_copy_func_t (void *); /* generic copy function */ typedef int sh_msg_func_t (const char *, ...); /* printf(3)-like */ typedef void sh_vmsg_func_t (const char *, ...); /* printf(3)-like */ diff --git a/hashlib.c b/hashlib.c index a9df3ed6..da760ba4 100644 --- a/hashlib.c +++ b/hashlib.c @@ -50,7 +50,7 @@ don't discard the upper 32 bits of the value, if present. */ #define HASH_BUCKET(s, t, h) (((h) = hash_string (s)) & ((t)->nbuckets - 1)) -static BUCKET_CONTENTS *copy_bucket_array (BUCKET_CONTENTS *, sh_string_func_t *); +static BUCKET_CONTENTS *copy_bucket_array (BUCKET_CONTENTS *, sh_copy_func_t *); static void hash_rehash (HASH_TABLE *, int); static void hash_grow (HASH_TABLE *); @@ -88,7 +88,7 @@ hash_size (HASH_TABLE *table) /* Copy a hash table bucket array. Call (*cpdata) to copy the data from each element. */ static BUCKET_CONTENTS * -copy_bucket_array (BUCKET_CONTENTS *ba, sh_string_func_t *cpdata) +copy_bucket_array (BUCKET_CONTENTS *ba, sh_copy_func_t *cpdata) { BUCKET_CONTENTS *new_bucket, *n, *e; @@ -171,7 +171,7 @@ hash_shrink (HASH_TABLE *table) /* Copy an entire hash table. (*cpdata) copies the data in each element. */ HASH_TABLE * -hash_copy (HASH_TABLE *table, sh_string_func_t *cpdata) +hash_copy (HASH_TABLE *table, sh_copy_func_t *cpdata) { HASH_TABLE *new_table; int i; diff --git a/hashlib.h b/hashlib.h index 0351ae9d..83ed99b6 100644 --- a/hashlib.h +++ b/hashlib.h @@ -45,7 +45,7 @@ typedef int hash_wfunc (BUCKET_CONTENTS *); /* Operations on tables as a whole */ extern HASH_TABLE *hash_create (int); -extern HASH_TABLE *hash_copy (HASH_TABLE *, sh_string_func_t *); +extern HASH_TABLE *hash_copy (HASH_TABLE *, sh_copy_func_t *); extern void hash_flush (HASH_TABLE *, sh_free_func_t *); extern void hash_dispose (HASH_TABLE *); extern void hash_walk (HASH_TABLE *, hash_wfunc *); diff --git a/po/hr.gmo b/po/hr.gmo index 862e37de..744a0df1 100644 Binary files a/po/hr.gmo and b/po/hr.gmo differ diff --git a/po/hr.po b/po/hr.po index 158119de..961ed2bd 100644 --- a/po/hr.po +++ b/po/hr.po @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: bash-5.2-rc1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-01-11 14:50-0500\n" -"PO-Revision-Date: 2025-02-19 16:48-0800\n" +"PO-Revision-Date: 2025-03-26 20:56-0700\n" "Last-Translator: Božidar Putanec \n" "Language-Team: Croatian \n" "Language: hr\n" @@ -224,7 +224,7 @@ msgstr "nevaljan oktalni broj" #: builtins/common.c:242 msgid "invalid hex number" -msgstr "nevaljan heksadecimalni broj" +msgstr "nevaljan heksadekadski broj" #: builtins/common.c:244 expr.c:1574 msgid "invalid number" @@ -360,7 +360,7 @@ msgstr "može se koristiti samo u funkciji" #: builtins/declare.def:437 msgid "cannot use `-f' to make functions" -msgstr "„-f” se ne može koristiti za definiranje funkcija" +msgstr "„-f” nije moguće koristiti za definiranje funkcija" #: builtins/declare.def:464 execute_cmd.c:6132 #, c-format @@ -682,7 +682,7 @@ msgstr "problem s raščlanjivanjem formata: %s" #: builtins/printf.def:919 msgid "missing hex digit for \\x" -msgstr "nema heksadecimalne znamenke za \\x" +msgstr "nema heksadekadske znamenke za \\x" #: builtins/printf.def:934 #, c-format @@ -1631,12 +1631,12 @@ msgstr "xtrace_set(): %d: nevaljan deskriptor datoteke" #: print_cmd.c:380 msgid "xtrace_set: NULL file pointer" -msgstr "xtrace_set(): pointer datoteke je NULL" +msgstr "xtrace_set(): pokazivač datoteke je NULL" #: print_cmd.c:384 #, c-format msgid "xtrace fd (%d) != fileno xtrace fp (%d)" -msgstr "deskriptor datoteke xtrace (%d) != broju datoteke u pointeru datoteke xtrace (%d)" +msgstr "deskriptor datoteke xtrace (%d) != broju datoteke u pokazivaču datoteke xtrace (%d)" #: print_cmd.c:1545 #, c-format @@ -2129,7 +2129,7 @@ msgstr "make_local_variable(): u trenutnom opsegu nema konteksta funkcije" #: variables.c:2661 #, c-format msgid "%s: variable may not be assigned value" -msgstr "%s: varijabli se ne može dodijeliti vrijednost" +msgstr "%s: varijabli nije moguće dodijeliti vrijednost" #: variables.c:2818 variables.c:2874 #, c-format @@ -2170,7 +2170,7 @@ msgstr "pop_var_context(): nije „global_variables” kontekst" #: variables.c:5410 msgid "pop_scope: head of shell_variables not a temporary environment scope" -msgstr "pop_scope(): vrh od „shell_variables” nije privremeni raspon valjanosti" +msgstr "pop_scope(): vrh od „shell_variables” nije privremeni doseg okružja" #: variables.c:6400 #, c-format @@ -2827,7 +2827,7 @@ msgstr "" " DIREKTORIJA.\n" "\n" " Završi s uspjehom ako je direktorij promijenjen i ako je\n" -" varijabla okoline PWD uspješno postavljena kad je dana opcija „-P”;\n" +" varijabla okruženja PWD uspješno postavljena kad je dana opcija „-P”;\n" " u suprotnom završi s kȏdom 1." #: builtins.c:425 @@ -3085,11 +3085,11 @@ msgstr "" " \\v vertikalni tabulator\n" " \\\\ backslash (\\)\n" " \\0NNN znak s ASCII kȏdom NNN (oktalni, 1 do 3 oktalne znamenke)\n" -" \\xHH osmobitni znak čija je vrijednost HH (heksadecimalna)\n" -" \\uHHHH unicode znak čija je vrijednost HHHH (heksadecimalna)\n" -" HHHH može biti od 1 do 4 heksadecimalne znamenke\n" -" \\UHHHHHHHH unicode znak čija je vrijednost HHHH (heksadecimalna)\n" -" HHHHHHHH može biti od 1 do 8 heksadecimalnih znamenki\n" +" \\xHH osmobitni znak čija je vrijednost HH (heksadekadska)\n" +" \\uHHHH unicode znak čija je vrijednost HHHH (heksadekadska)\n" +" HHHH može biti od 1 do 4 heksadekadske znamenke\n" +" \\UHHHHHHHH unicode znak čija je vrijednost HHHH (heksadekadska)\n" +" HHHHHHHH može biti od 1 do 8 heksadekadskih znamenki\n" "\n" " Završi s uspjehom osim ako se ne dogodi greška pri pisanju." @@ -3951,7 +3951,7 @@ msgstr "" " -P ne razriješi simbolične linkove pri izvršavanju naredbi poput „cd”\n" " koje promijene trenutni direktorij\n" " -p uključi privilegirani način: datoteke BASH_ENV i ENV se zanemare,\n" -" funkcije ljuske se ne uvoze iz okoline, a zanemari se i\n" +" funkcije ljuske se ne uvoze iz okruženja, a zanemari se i\n" " sve SHELLOPTS; taj način se automatski aktivira kad god se stvarni\n" " i efektivni UID i GID ne podudaraju. Isključivanje ove opcije\n" " učini da je efektivni UID i GID isti kao i stvarni UID i GID.\n" @@ -4758,7 +4758,7 @@ msgstr "" " trošenja vremena: ukupno potrošeno vrijeme, CPU vrijeme potrošeno\n" " korisnikom i CPU vrijeme potrošeno sustavom za izvršavanje naredbi.\n" "\n" -" Izlazni format se može prilagoditi s varijablom okoline TIMEFORMAT.\n" +" Izlazni format se može prilagoditi s varijablom okruženja TIMEFORMAT.\n" " Opcija „-p” zanemari TIMEFORMAT i ispiše izlaz u prenosivom POSIX\n" " formatu.\n" "\n" diff --git a/shell.c b/shell.c index b3b51d1d..e59029cc 100644 --- a/shell.c +++ b/shell.c @@ -1738,7 +1738,18 @@ set_bash_input (void) if (interactive && no_line_editing == 0) with_input_from_stdin (); else if (interactive == 0) - with_input_from_buffered_stream (default_buffered_input, dollar_vars[0]); + { + errno = 0; + with_input_from_buffered_stream (default_buffered_input, dollar_vars[0]); + if (get_buffered_stream (default_buffered_input) == NULL) + { + last_command_exit_value = EX_NOINPUT; + if (errno != 0) + sys_error ("%s", _("error creating buffered stream")); + else + report_error ("%s", _("error creating buffered stream")); + } + } else with_input_from_stream (default_input, dollar_vars[0]); } diff --git a/subst.c b/subst.c index 5f4dfc75..284d8e0e 100644 --- a/subst.c +++ b/subst.c @@ -7003,9 +7003,9 @@ function_substitute (char *string, int quoted, int flags) subst_assign_varlist = 0; - push_context (lambdafunc.name, 1, temporary_env); /* make local variables work */ temporary_env = 0; - this_shell_function = &lambdafunc; + push_context (lambdafunc.name, 1, temporary_env); /* make local variables work */ + this_shell_function = &lambdafunc; unwind_protect_int (verbose_flag); change_flag ('v', FLAG_OFF); diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 0afae3fd..2139f171 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -: ${BUILD_DIR:==/usr/local/build/bash/bash-current} +: ${BUILD_DIR:=/usr/local/build/bash/bash-current} THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/builtins.right b/tests/builtins.right index 1c582827..d708c188 100644 --- a/tests/builtins.right +++ b/tests/builtins.right @@ -426,7 +426,7 @@ SEE ALSO bash(1) IMPLEMENTATION - Copyright (C) 2024 Free Software Foundation, Inc. + Copyright (C) 2025 Free Software Foundation, Inc. These shell commands are defined internally. Type `help' to see this list. Type `help name' to find out more about the function `name'. diff --git a/variables.c b/variables.c index 3639487f..37624e46 100644 --- a/variables.c +++ b/variables.c @@ -3656,7 +3656,7 @@ assign_in_env (const WORD_DESC *word, int flags) /* */ /* **************************************************************** */ -#ifdef INCLUDE_UNUSED +#if defined (INCLUDE_UNUSED) /* Copy VAR to a new data structure and return that structure. */ SHELL_VAR * copy_variable (SHELL_VAR *var) @@ -4685,6 +4685,31 @@ flush_temporary_env (void) } } +#if defined (INCLUDE_UNUSED) +void * +copyvar (void *v) +{ + SHELL_VAR *new; + new = copy_variable ((SHELL_VAR *)v); + return new; +} + +HASH_TABLE * +copy_vartab (HASH_TABLE *table) +{ + HASH_TABLE *newtab; + + newtab = table ? hash_copy (table, copyvar) : NULL; + return newtab; +} + +HASH_TABLE * +copy_temporary_env (void) +{ + return copy_vartab (temporary_env); +} +#endif + /* **************************************************************** */ /* */ /* Creating and manipulating the environment */ diff --git a/variables.h b/variables.h index 8b33ea6f..201db365 100644 --- a/variables.h +++ b/variables.h @@ -388,9 +388,12 @@ extern void dispose_builtin_env (void); extern void merge_temporary_env (void); extern void merge_function_temporary_env (void); extern void flush_temporary_env (void); +extern HASH_TABLE *copy_temporary_env (void); extern void merge_builtin_env (void); extern void kill_all_local_variables (void); +extern HASH_TABLE *copy_vartab (HASH_TABLE *); + extern void set_var_read_only (char *); extern void set_func_read_only (const char *); extern void set_var_auto_export (char *);