From 7f7ee0e9c6766ff5d3de542d03c59590c4a5a44a Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 17 Jul 2023 17:35:59 -0400 Subject: [PATCH] fix for leak when completing command word with glob pattern that matches multiple files; preserve export attribute when unsetting local variable in case it is reset; fix for using nl_langinfo when performing charset conversions --- CWRU/CWRU.chlog | 19 +++++++++++++++++++ MANIFEST | 2 +- bashline.c | 6 +++++- lib/sh/unicode.c | 6 +++++- variables.c | 6 ++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 5ad32a9d..b9f94951 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -7124,3 +7124,22 @@ jobs.c that we use IS_ASYNC to determine whether to give the terminal back to the shell's process group. From a report by Grisha Levit + +bashline.c + - command_word_completion_function: if we have a glob pattern that + expands to multiple words, dispose of the list before returning NULL. + From a report by Grisha Levit + +variables.c + - makunbound: if we're unsetting a local variable, preserve the export + attribute even if the variable's not in the temporary environment + Tentative fix, compatible with other POSIX shells (except the BSD + variants of ash) + + 7/12 + ---- +lib/sh/unicode.c + - include if HAVE_LANGINFO_CODESET is defined, use + nl_langinfo (CODESET) if HAVE_LANGINFO_CODESET is define, since + we no longer check for nl_langinfo. This is what locale.c does. + diff --git a/MANIFEST b/MANIFEST index 36ef4d41..2643645d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -973,7 +973,7 @@ tests/assoc16.sub f tests/assoc17.sub f tests/assoc18.sub f tests/assoc19.sub f -`tests/attr.tests f +tests/attr.tests f tests/attr.right f tests/attr1.sub f tests/attr2.sub f diff --git a/bashline.c b/bashline.c index 0e5373ab..2fb00e82 100644 --- a/bashline.c +++ b/bashline.c @@ -2192,7 +2192,11 @@ globword: local_index = 0; if (glob_matches[1] && rl_completion_type == TAB) /* multiple matches are bad */ - return ((char *)NULL); + { + strvec_dispose (glob_matches); + glob_matches = (char **)NULL; + return ((char *)NULL); + } } while (val = glob_matches[local_index++]) diff --git a/lib/sh/unicode.c b/lib/sh/unicode.c index 24d3d50d..87bb5c80 100644 --- a/lib/sh/unicode.c +++ b/lib/sh/unicode.c @@ -35,6 +35,10 @@ # include #endif +#if HAVE_LANGINFO_CODESET +# include +#endif + #include #ifndef USHORT_MAX @@ -267,7 +271,7 @@ u32cconv (unsigned long c, char *s) { #if HAVE_LOCALE_CHARSET charset = locale_charset (); -#elif HAVE_NL_LANGINFO +#elif HAVE_LANGINFO_CODESET charset = nl_langinfo (CODESET); #else charset = stub_charset (); diff --git a/variables.c b/variables.c index 05a0daa0..854d39f8 100644 --- a/variables.c +++ b/variables.c @@ -3942,10 +3942,16 @@ makunbound (const char *name, VAR_CONTEXT *vc) FREE (nameref_cell (old_var)); else FREE (value_cell (old_var)); +#if 0 /* Reset the attributes. Preserve the export attribute if the variable came from a temporary environment. Make sure it stays local, and make it invisible. */ old_var->attributes = (exported_p (old_var) && tempvar_p (old_var)) ? att_exported : 0; +#else /* TAG:bash-5.3 look at this again */ + /* Reset the attributes, but preserve the export attribute. + Make sure it stays local, and make it invisible. */ + old_var->attributes = exported_p (old_var) ? att_exported : 0; +#endif VSETATTR (old_var, att_local); VSETATTR (old_var, att_invisible); var_setvalue (old_var, (char *)NULL);