!112 sync patches from bash community
From: @hongjinghao Reviewed-by: @openeuler-basic Signed-off-by: @openeuler-basic
This commit is contained in:
commit
74d9a85e78
@ -0,0 +1,78 @@
|
|||||||
|
From 7f7ee0e9c6766ff5d3de542d03c59590c4a5a44a Mon Sep 17 00:00:00 2001
|
||||||
|
From: Chet Ramey <chet.ramey@case.edu>
|
||||||
|
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
|
||||||
|
|
||||||
|
---
|
||||||
|
bashline.c | 6 +++++-
|
||||||
|
lib/sh/unicode.c | 6 +++++-
|
||||||
|
variables.c | 6 ++++++
|
||||||
|
3 files changed, 16 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/bashline.c b/bashline.c
|
||||||
|
index c85b05b..2e0c0c7 100644
|
||||||
|
--- a/bashline.c
|
||||||
|
+++ b/bashline.c
|
||||||
|
@@ -2203,7 +2203,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 d781353..9e3c9da 100644
|
||||||
|
--- a/lib/sh/unicode.c
|
||||||
|
+++ b/lib/sh/unicode.c
|
||||||
|
@@ -35,6 +35,10 @@
|
||||||
|
# include <iconv.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+#if HAVE_LANGINFO_CODESET
|
||||||
|
+# include <langinfo.h>
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#include <xmalloc.h>
|
||||||
|
|
||||||
|
#ifndef USHORT_MAX
|
||||||
|
@@ -277,7 +281,7 @@ u32cconv (c, 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 1a0c2c4..f08575a 100644
|
||||||
|
--- a/variables.c
|
||||||
|
+++ b/variables.c
|
||||||
|
@@ -4016,10 +4016,16 @@ makunbound (name, 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);
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
@ -0,0 +1,266 @@
|
|||||||
|
From b8b75527c24a37d93a213dcafd85609bbd147330 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Chet Ramey <chet.ramey@case.edu>
|
||||||
|
Date: Tue, 20 Jun 2023 11:10:39 -0400
|
||||||
|
Subject: [PATCH] fix for nofork comsub command printing; fix for crash caused
|
||||||
|
by tempvar assignment converted to an array in a function
|
||||||
|
|
||||||
|
---
|
||||||
|
arrayfunc.c | 13 ++++++++++
|
||||||
|
arrayfunc.h | 1 +
|
||||||
|
builtins/declare.def | 14 ++++++++---
|
||||||
|
print_cmd.c | 12 +++++----
|
||||||
|
shell.h | 2 ++
|
||||||
|
subst.h | 1 +
|
||||||
|
variables.c | 59 ++++++++++++++++++++++++++++++--------------
|
||||||
|
7 files changed, 74 insertions(+), 28 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/arrayfunc.c b/arrayfunc.c
|
||||||
|
index 2c05d15..74a5a80 100644
|
||||||
|
--- a/arrayfunc.c
|
||||||
|
+++ b/arrayfunc.c
|
||||||
|
@@ -147,6 +147,19 @@ convert_var_to_assoc (var)
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
+/* Copy the array (ARRAY *) or assoc (HASH_TABLE *) from variable V1 to V2,
|
||||||
|
+ and return V2. */
|
||||||
|
+SHELL_VAR *
|
||||||
|
+arrayvar_copyval (SHELL_VAR *v1, SHELL_VAR *v2)
|
||||||
|
+{
|
||||||
|
+ FREE (value_cell (v2));
|
||||||
|
+ if (array_p (v1))
|
||||||
|
+ var_setarray (v2, array_copy (array_cell (v1)));
|
||||||
|
+ else if (assoc_p (v1))
|
||||||
|
+ var_setassoc (v2, assoc_copy (assoc_cell (v1)));
|
||||||
|
+ return v2;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
char *
|
||||||
|
make_array_variable_value (entry, ind, key, value, flags)
|
||||||
|
SHELL_VAR *entry;
|
||||||
|
diff --git a/arrayfunc.h b/arrayfunc.h
|
||||||
|
index 69112b5..735437d 100644
|
||||||
|
--- a/arrayfunc.h
|
||||||
|
+++ b/arrayfunc.h
|
||||||
|
@@ -75,6 +75,7 @@ extern int array_expand_once;
|
||||||
|
|
||||||
|
extern SHELL_VAR *convert_var_to_array PARAMS((SHELL_VAR *));
|
||||||
|
extern SHELL_VAR *convert_var_to_assoc PARAMS((SHELL_VAR *));
|
||||||
|
+extern SHELL_VAR *arrayvar_copyval (SHELL_VAR *, SHELL_VAR *);
|
||||||
|
|
||||||
|
extern char *make_array_variable_value PARAMS((SHELL_VAR *, arrayind_t, char *, char *, int));
|
||||||
|
|
||||||
|
diff --git a/builtins/declare.def b/builtins/declare.def
|
||||||
|
index 54db59c..d269c77 100644
|
||||||
|
--- a/builtins/declare.def
|
||||||
|
+++ b/builtins/declare.def
|
||||||
|
@@ -1002,20 +1002,26 @@ restart_new_var_name:
|
||||||
|
if ((flags_on & (att_exported|att_readonly)) && tempvar_p (var))
|
||||||
|
{
|
||||||
|
SHELL_VAR *tv;
|
||||||
|
- char *tvalue;
|
||||||
|
|
||||||
|
tv = find_tempenv_variable (name_cell (var));
|
||||||
|
if (tv)
|
||||||
|
{
|
||||||
|
- tvalue = var_isset (var) ? savestring (value_cell (var)) : savestring ("");
|
||||||
|
- tv = bind_variable (name_cell (var), tvalue, 0);
|
||||||
|
+ /* We don't bother with modifying the temporary env because
|
||||||
|
+ we're already using it. */
|
||||||
|
+ tv = bind_variable (name_cell (var), value_cell (var), ASS_NOTEMPENV);
|
||||||
|
+
|
||||||
|
if (tv)
|
||||||
|
{
|
||||||
|
+#if defined (ARRAY_VARS)
|
||||||
|
+ /* copy array value if array variable */
|
||||||
|
+ if ((array_p (var) || assoc_p (var)))
|
||||||
|
+ arrayvar_copyval (var, tv);
|
||||||
|
+#endif
|
||||||
|
+ /* then copy attributes */
|
||||||
|
tv->attributes |= var->attributes & ~att_tempvar;
|
||||||
|
if (tv->context > 0)
|
||||||
|
VSETATTR (tv, att_propagate);
|
||||||
|
}
|
||||||
|
- free (tvalue);
|
||||||
|
}
|
||||||
|
VSETATTR (var, att_propagate);
|
||||||
|
}
|
||||||
|
diff --git a/print_cmd.c b/print_cmd.c
|
||||||
|
index b815494..9719f62 100644
|
||||||
|
--- a/print_cmd.c
|
||||||
|
+++ b/print_cmd.c
|
||||||
|
@@ -699,7 +699,7 @@ print_group_command (group_command)
|
||||||
|
group_command_nesting++;
|
||||||
|
cprintf ("{ ");
|
||||||
|
|
||||||
|
- if (inside_function_def == 0)
|
||||||
|
+ if (inside_function_def == 0 /* && pretty_print_mode == 0 */)
|
||||||
|
skip_this_indent++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@@ -713,7 +713,7 @@ print_group_command (group_command)
|
||||||
|
make_command_string_internal (group_command->command);
|
||||||
|
PRINT_DEFERRED_HEREDOCS ("");
|
||||||
|
|
||||||
|
- if (inside_function_def)
|
||||||
|
+ if (inside_function_def /* || pretty_print_mode */)
|
||||||
|
{
|
||||||
|
cprintf ("\n");
|
||||||
|
indentation -= indentation_amount;
|
||||||
|
@@ -1511,9 +1511,11 @@ indent (amount)
|
||||||
|
static void
|
||||||
|
semicolon ()
|
||||||
|
{
|
||||||
|
- if (command_string_index > 0 &&
|
||||||
|
- (the_printed_command[command_string_index - 1] == '&' ||
|
||||||
|
- the_printed_command[command_string_index - 1] == '\n'))
|
||||||
|
+ if ((command_string_index > 0 &&
|
||||||
|
+ the_printed_command[command_string_index - 1] == '\n') ||
|
||||||
|
+ (command_string_index > 1 &&
|
||||||
|
+ the_printed_command[command_string_index - 1] == '&' &&
|
||||||
|
+ the_printed_command[command_string_index - 2] == ' '))
|
||||||
|
return;
|
||||||
|
cprintf (";");
|
||||||
|
}
|
||||||
|
diff --git a/shell.h b/shell.h
|
||||||
|
index 6e44bca..bce7ef6 100644
|
||||||
|
--- a/shell.h
|
||||||
|
+++ b/shell.h
|
||||||
|
@@ -107,6 +107,8 @@ extern int indirection_level;
|
||||||
|
extern int shell_compatibility_level;
|
||||||
|
extern int running_under_emacs;
|
||||||
|
|
||||||
|
+extern int pretty_print_mode;
|
||||||
|
+
|
||||||
|
extern int posixly_correct;
|
||||||
|
extern int no_line_editing;
|
||||||
|
|
||||||
|
diff --git a/subst.h b/subst.h
|
||||||
|
index 28cc920..723079b 100644
|
||||||
|
--- a/subst.h
|
||||||
|
+++ b/subst.h
|
||||||
|
@@ -55,6 +55,7 @@
|
||||||
|
#define ASS_NOEVAL 0x0100 /* don't evaluate value as expression */
|
||||||
|
#define ASS_NOLONGJMP 0x0200 /* don't longjmp on fatal assignment error */
|
||||||
|
#define ASS_NOINVIS 0x0400 /* don't resolve local invisible variables */
|
||||||
|
+#define ASS_NOTEMPENV 0x2000 /* don't assign into temporary environment */
|
||||||
|
#define ASS_ALLOWALLSUB 0x0800 /* allow * and @ as associative array keys */
|
||||||
|
#define ASS_ONEWORD 0x1000 /* don't check array subscripts, assume higher level has done that */
|
||||||
|
|
||||||
|
diff --git a/variables.c b/variables.c
|
||||||
|
index 1a0c2c4..468dd6b 100644
|
||||||
|
--- a/variables.c
|
||||||
|
+++ b/variables.c
|
||||||
|
@@ -281,6 +281,8 @@ static SHELL_VAR *new_shell_variable PARAMS((const char *));
|
||||||
|
static SHELL_VAR *make_new_variable PARAMS((const char *, HASH_TABLE *));
|
||||||
|
static SHELL_VAR *bind_variable_internal PARAMS((const char *, char *, HASH_TABLE *, int, int));
|
||||||
|
|
||||||
|
+static void init_shell_variable (SHELL_VAR *);
|
||||||
|
+
|
||||||
|
static void dispose_variable_value PARAMS((SHELL_VAR *));
|
||||||
|
static void free_variable_hash_data PARAMS((PTR_T));
|
||||||
|
|
||||||
|
@@ -2699,6 +2701,21 @@ make_local_variable (name, flags)
|
||||||
|
new_var = make_new_variable (name, vc->table);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
+#if 0
|
||||||
|
+ /* This handles the case where a variable is found in both the temporary
|
||||||
|
+ environment *and* declared as a local variable. If we want to avoid
|
||||||
|
+ multiple entries with the same name in VC->table (that might mess up
|
||||||
|
+ unset), we need to use the existing variable entry and destroy the
|
||||||
|
+ current value. Currently disabled because it doesn't matter -- the
|
||||||
|
+ right things happen. */
|
||||||
|
+ new_var = 0;
|
||||||
|
+ if (was_tmpvar && (new_var = hash_lookup (name, vc->table)))
|
||||||
|
+ {
|
||||||
|
+ dispose_variable_value (new_var);
|
||||||
|
+ init_variable (new_var);
|
||||||
|
+ }
|
||||||
|
+ if (new_var == 0)
|
||||||
|
+#endif
|
||||||
|
new_var = make_new_variable (name, vc->table);
|
||||||
|
|
||||||
|
/* If we found this variable in one of the temporary environments,
|
||||||
|
@@ -2758,16 +2775,9 @@ set_local_var_flags:
|
||||||
|
return (new_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
-/* Create a new shell variable with name NAME. */
|
||||||
|
-static SHELL_VAR *
|
||||||
|
-new_shell_variable (name)
|
||||||
|
- const char *name;
|
||||||
|
+static void
|
||||||
|
+init_variable (SHELL_VAR *entry)
|
||||||
|
{
|
||||||
|
- SHELL_VAR *entry;
|
||||||
|
-
|
||||||
|
- entry = (SHELL_VAR *)xmalloc (sizeof (SHELL_VAR));
|
||||||
|
-
|
||||||
|
- entry->name = savestring (name);
|
||||||
|
var_setvalue (entry, (char *)NULL);
|
||||||
|
CLEAR_EXPORTSTR (entry);
|
||||||
|
|
||||||
|
@@ -2780,7 +2790,18 @@ new_shell_variable (name)
|
||||||
|
make_local_variable has the responsibility of changing the
|
||||||
|
variable context. */
|
||||||
|
entry->context = 0;
|
||||||
|
+}
|
||||||
|
|
||||||
|
+/* Create a new shell variable with name NAME. */
|
||||||
|
+static SHELL_VAR *
|
||||||
|
+new_shell_variable (const char *name)
|
||||||
|
+{
|
||||||
|
+ SHELL_VAR *entry;
|
||||||
|
+
|
||||||
|
+ entry = (SHELL_VAR *)xmalloc (sizeof (SHELL_VAR));
|
||||||
|
+
|
||||||
|
+ entry->name = savestring (name);
|
||||||
|
+ init_variable (entry);
|
||||||
|
return (entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -3268,8 +3289,9 @@ bind_variable (name, value, flags)
|
||||||
|
and, if found, modify the value there before modifying it in the
|
||||||
|
shell_variables table. This allows sourced scripts to modify values
|
||||||
|
given to them in a temporary environment while modifying the variable
|
||||||
|
- value that the caller sees. */
|
||||||
|
- if (temporary_env && value) /* XXX - can value be null here? */
|
||||||
|
+ value that the caller sees. The caller can inhibit this by setting
|
||||||
|
+ ASS_NOTEMPENV in FLAGS. */
|
||||||
|
+ if (temporary_env && value && (flags & ASS_NOTEMPENV) == 0) /* XXX - can value be null here? */
|
||||||
|
bind_tempenv_variable (name, value);
|
||||||
|
|
||||||
|
/* XXX -- handle local variables here. */
|
||||||
|
@@ -4624,6 +4646,11 @@ push_temp_var (data)
|
||||||
|
|
||||||
|
v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
|
||||||
|
|
||||||
|
+#if defined (ARRAY_VARS)
|
||||||
|
+ if (v && (array_p (var) || assoc_p (var)))
|
||||||
|
+ arrayvar_copyval (var, v);
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
/* XXX - should we set the context here? It shouldn't matter because of how
|
||||||
|
assign_in_env works, but we do it anyway. */
|
||||||
|
if (v)
|
||||||
|
@@ -5371,14 +5398,8 @@ push_posix_tempvar_internal (var, isbltin)
|
||||||
|
|
||||||
|
#if defined (ARRAY_VARS)
|
||||||
|
if (v && (array_p (var) || assoc_p (var)))
|
||||||
|
- {
|
||||||
|
- FREE (value_cell (v));
|
||||||
|
- if (array_p (var))
|
||||||
|
- var_setarray (v, array_copy (array_cell (var)));
|
||||||
|
- else
|
||||||
|
- var_setassoc (v, assoc_copy (assoc_cell (var)));
|
||||||
|
- }
|
||||||
|
-#endif
|
||||||
|
+ arrayvar_copyval (var, v);
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
dispose_variable (var);
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
28
backport-fix-small-memleak-in-globbing.patch
Normal file
28
backport-fix-small-memleak-in-globbing.patch
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
From 829aad36dbbeee462fa142fe2c571fd7ab735ba8 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Chet Ramey <chet.ramey@case.edu>
|
||||||
|
Date: Mon, 26 Jun 2023 17:09:08 -0400
|
||||||
|
Subject: [PATCH] backport part of patch to fix small memleak in globbing
|
||||||
|
|
||||||
|
---
|
||||||
|
lib/glob/glob.c | 6 ++++++
|
||||||
|
1 file changed, 6 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/lib/glob/glob.c b/lib/glob/glob.c
|
||||||
|
index b66af85..e4283bd 100644
|
||||||
|
--- a/lib/glob/glob.c
|
||||||
|
+++ b/lib/glob/glob.c
|
||||||
|
@@ -1446,6 +1446,12 @@ glob_filename (pathname, flags)
|
||||||
|
free ((char *) array);
|
||||||
|
else if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
|
||||||
|
free (temp_results); /* expanding ** case above */
|
||||||
|
+ else if (array == temp_results)
|
||||||
|
+ /* If array == temp_results, either we assigned it above or
|
||||||
|
+ glob_dir_to_array returned temp_results because the dirname
|
||||||
|
+ was the empty string. In any case, we assume temp_results
|
||||||
|
+ has not been freed, and free it here. */
|
||||||
|
+ free (temp_results);
|
||||||
|
|
||||||
|
if (shouldbreak)
|
||||||
|
break;
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
Name: bash
|
Name: bash
|
||||||
Version: 5.2.15
|
Version: 5.2.15
|
||||||
Release: 4
|
Release: 5
|
||||||
Summary: It is the Bourne Again Shell
|
Summary: It is the Bourne Again Shell
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
URL: https://www.gnu.org/software/bash
|
URL: https://www.gnu.org/software/bash
|
||||||
@ -32,6 +32,10 @@ Patch138: enable-dot-logout-and-source-bashrc-through-ssh.patch
|
|||||||
Patch139: cd-alias.patch
|
Patch139: cd-alias.patch
|
||||||
Patch140: bash-5.1-sw.patch
|
Patch140: bash-5.1-sw.patch
|
||||||
|
|
||||||
|
Patch6000: backport-fix-for-nofork-comsub-command-printing-fix-for-crash.patch
|
||||||
|
Patch6001: backport-fix-small-memleak-in-globbing.patch
|
||||||
|
Patch6002: backport-fix-for-leak-when-completing-command-word-with-glob-.patch
|
||||||
|
|
||||||
BuildRequires: gcc bison texinfo autoconf ncurses-devel
|
BuildRequires: gcc bison texinfo autoconf ncurses-devel
|
||||||
# Required for bash tests
|
# Required for bash tests
|
||||||
BuildRequires: glibc-all-langpacks
|
BuildRequires: glibc-all-langpacks
|
||||||
@ -158,6 +162,9 @@ make check
|
|||||||
%exclude %{_infodir}/dir
|
%exclude %{_infodir}/dir
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Dec 4 2023 hongjinghao <hongjinghao@huawei.com> -5.2.15-5
|
||||||
|
- sync patches from bash community
|
||||||
|
|
||||||
* Tue Aug 29 2023 liutie <liutie4@huawei.com> -5.2.15-4
|
* Tue Aug 29 2023 liutie <liutie4@huawei.com> -5.2.15-4
|
||||||
- Type:enhancement
|
- Type:enhancement
|
||||||
- ID:NA
|
- ID:NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user