7 Bug-Reported-by: Stephane Chazelas <stephane.chazelas@gmail.com>
13 Under certain circumstances, bash will execute user code while processing the
14 environment for exported function definitions.
16 Patch (apply with `patch -p0'):
18 --- a/builtins/common.h
19 +++ b/builtins/common.h
21 #define SEVAL_RESETLINE 0x010
22 #define SEVAL_PARSEONLY 0x020
23 #define SEVAL_NOLONGJMP 0x040
24 +#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
25 +#define SEVAL_ONECMD 0x100 /* only allow a single command */
27 /* Flags for describe_command, shared between type.def and command.def */
28 #define CDESC_ALL 0x001 /* type -a */
29 --- a/builtins/evalstring.c
30 +++ b/builtins/evalstring.c
31 @@ -308,6 +308,14 @@ parse_and_execute (string, from_file, fl
33 struct fd_bitmap *bitmap;
35 + if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
37 + internal_warning ("%s: ignoring function definition attempt", from_file);
38 + should_jump_to_top_level = 0;
39 + last_result = last_command_exit_value = EX_BADUSAGE;
43 bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
44 begin_unwind_frame ("pe_dispose");
45 add_unwind_protect (dispose_fd_bitmap, bitmap);
46 @@ -368,6 +376,9 @@ parse_and_execute (string, from_file, fl
47 dispose_command (command);
48 dispose_fd_bitmap (bitmap);
49 discard_unwind_frame ("pe_dispose");
51 + if (flags & SEVAL_ONECMD)
58 @@ -358,13 +358,11 @@ initialize_shell_variables (env, privmod
59 temp_string[char_index] = ' ';
60 strcpy (temp_string + char_index + 1, string);
62 - if (posixly_correct == 0 || legal_identifier (name))
63 - parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);
65 - /* Ancient backwards compatibility. Old versions of bash exported
66 - functions like name()=() {...} */
67 - if (name[char_index - 1] == ')' && name[char_index - 2] == '(')
68 - name[char_index - 2] = '\0';
69 + /* Don't import function names that are invalid identifiers from the
70 + environment, though we still allow them to be defined as shell
72 + if (legal_identifier (name))
73 + parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
75 if (temp_var = find_function (name))
77 @@ -381,10 +379,6 @@ initialize_shell_variables (env, privmod
78 last_command_exit_value = 1;
79 report_error (_("error importing function definition for `%s'"), name);
83 - if (name[char_index - 1] == ')' && name[char_index - 2] == '\0')
84 - name[char_index - 2] = '('; /* ) */
86 #if defined (ARRAY_VARS)
90 @@ -8047,7 +8047,9 @@ comsub:
94 - else if (var = find_variable_last_nameref (temp1))
95 + else if (var && (invisible_p (var) || var_isset (var) == 0))
96 + temp = (char *)NULL;
97 + else if ((var = find_variable_last_nameref (temp1)) && var_isset (var) && invisible_p (var) == 0)
99 temp = nameref_cell (var);
100 #if defined (ARRAY_VARS)
104 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
105 looks for to find the patch level (for the sccs version string). */
107 -#define PATCHLEVEL 24
108 +#define PATCHLEVEL 25
110 #endif /* _PATCHLEVEL_H_ */