From a6767763de5e7859107711b166a64a9e4a77a8ae Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 31 Mar 2025 09:58:59 -0400 Subject: [PATCH] fix for multiple assignment statements containing nofork comsubs preceding a command; fix for possible issue with invalid bash input fd --- CHANGES | 8 +++++++- CHANGES-5.3 | 8 +++++++- CWRU/CWRU.chlog | 16 ++++++++++++++++ general.h | 1 + hashlib.c | 6 +++--- hashlib.h | 2 +- po/hr.gmo | Bin 178300 -> 178307 bytes po/hr.po | 32 ++++++++++++++++---------------- shell.c | 13 ++++++++++++- subst.c | 4 ++-- tests/RUN-ONE-TEST | 2 +- tests/builtins.right | 2 +- variables.c | 27 ++++++++++++++++++++++++++- variables.h | 3 +++ 14 files changed, 96 insertions(+), 28 deletions(-) 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 862e37dede7004e2c1ffdc89db86f626b87804a5..744a0df1ea6e0dee473d043c5567e66cc68ca1d5 100644 GIT binary patch delta 4015 zcmYM$dz{Zz9>?*|_ZV^=ml#86#w}}%%eaNH#?mHun=D}0*MXg2?euEz%WJ`UoG&!a-u_6KhoDizP*D;VN&ta2l;T6h*~Vlh_7=pX%j4N$3l z2+5p1fkY;>Q8bj}iAVr!F4n-M7>k=w59~*U^biihWB3_gR_~|49wnqViv!zCRrS0b zSVtmosg$!6Y*5}(Db48tKj@L5e~r-?vf ztSec0sd~yV%fKTgF#XIDHsD_JFe-`ZW@qonirbiOveRZ&nLu zS@c`9bk>mmo2{HR=KXepMpG^n<4KHf?d&PM(Z*Rht`BJEO19r{oUWYWPQ28?*(Mge zsbH)!90#Ewzuc1w8-FFlYPu;;~OSn@K-@q$?@LwHPXQ+iB=U(?>bm zLn!B=wo!|xT}dvJQQK?~#^F?~f-5nVh2~)*{cGd>JasZ$$@$S3mBL=A8hQ$w;T+^h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q6&2(XOSWOhL{qT~u0);iFnWp;wdz}ZXmj2X8_|!$^*9nX@ zK+SL@{Slai8&Gq59W^2?4p@^hj{Zik-=Z$ab&&n96QmzB@(ON4{j!Is6Uv`$ZUayw z5`|jr(^0qUV$>8IM@`+QsLx%*VfY)i#h633$fu&73u{qp>gXZ2&FNh(Xc74zwhs=% z2>NNL5!r^C`}3$Z@f3A|VMpu&;!snRjGE(A)P>~YP~3_7vwQ<}q2{QOvFPunp##rC zJ#ve%4IV^2fc}OWy8oj7>ct+jD_@3M8=s&q=ppKn+xfVyp^2#5I^XLd)QDU~{jd%v zY^2@eY3PJgQA3rB!B~u1rIn}?Ttp3hgOm3EK}XbG6OLL#6TSU+a1{NIP*d|OYGmq_ z+oBBcIu4nqn-tQ}kR8Qj`~r35Z7OUCN1zUrwJbNZJU7(YGt?&{EIiT`-hWWvfnmJ| zmUo}&{M)Z_cB(5g)ipb-`c!$yBB!lyy{wG1%+&Juwa(_9-u90@O;rbP`|uc3)wBL< zX|q!@GK+KaP4x42Wxnb6y!{~GBsR3qq;xHw^NrKGc*+tJ>b+gQVu>mD`TvPWtTRuW zJ--{j!{pR`-uY~|*=Ky`rewdFmFb$Fl98U0nU$TBR?L~;S6;Bk%xPIaEi)%|?!4mj t<)&3}P=$#O@mz4do|2Q5lR7Kam7eNK8lRXbd9I|GC@;?t8+=T!D 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 *);