diff options
Diffstat (limited to 'meta/recipes-extended/bash/bash/Fix-for-bash-exported-function-namespace-change.patch')
-rw-r--r-- | meta/recipes-extended/bash/bash/Fix-for-bash-exported-function-namespace-change.patch | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/meta/recipes-extended/bash/bash/Fix-for-bash-exported-function-namespace-change.patch b/meta/recipes-extended/bash/bash/Fix-for-bash-exported-function-namespace-change.patch new file mode 100644 index 0000000000..1faab04659 --- /dev/null +++ b/meta/recipes-extended/bash/bash/Fix-for-bash-exported-function-namespace-change.patch | |||
@@ -0,0 +1,175 @@ | |||
1 | Fix for exported function namespace change | ||
2 | |||
3 | Upstream-Status: Backport | ||
4 | |||
5 | Downloaded from: http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-027 | ||
6 | |||
7 | Author: Chet Ramey <chet.ramey@case.edu> | ||
8 | Signed-off-by: Sona Sarmadi <sona.sarmadi@enea.com> | ||
9 | |||
10 | |||
11 | BASH PATCH REPORT | ||
12 | ================= | ||
13 | |||
14 | Bash-Release: 4.3 | ||
15 | Patch-ID: bash43-027 | ||
16 | |||
17 | Bug-Reported-by: Florian Weimer <fweimer@redhat.com> | ||
18 | Bug-Reference-ID: | ||
19 | Bug-Reference-URL: | ||
20 | |||
21 | Bug-Description: | ||
22 | |||
23 | This patch changes the encoding bash uses for exported functions to avoid | ||
24 | clashes with shell variables and to avoid depending only on an environment | ||
25 | variable's contents to determine whether or not to interpret it as a shell | ||
26 | function. | ||
27 | --- | ||
28 | diff -ruN a/variables.c b/variables.c | ||
29 | --- a/variables.c 2014-09-30 10:21:12.481674914 +0200 | ||
30 | +++ b/variables.c 2014-09-30 10:21:40.820459492 +0200 | ||
31 | @@ -83,6 +83,11 @@ | ||
32 | |||
33 | #define ifsname(s) ((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && (s)[3] == '\0') | ||
34 | |||
35 | +#define BASHFUNC_PREFIX "BASH_FUNC_" | ||
36 | +#define BASHFUNC_PREFLEN 10 /* == strlen(BASHFUNC_PREFIX */ | ||
37 | +#define BASHFUNC_SUFFIX "%%" | ||
38 | +#define BASHFUNC_SUFFLEN 2 /* == strlen(BASHFUNC_SUFFIX) */ | ||
39 | + | ||
40 | extern char **environ; | ||
41 | |||
42 | /* Variables used here and defined in other files. */ | ||
43 | @@ -279,7 +284,7 @@ | ||
44 | static void propagate_temp_var __P((PTR_T)); | ||
45 | static void dispose_temporary_env __P((sh_free_func_t *)); | ||
46 | |||
47 | -static inline char *mk_env_string __P((const char *, const char *)); | ||
48 | +static inline char *mk_env_string __P((const char *, const char *, int)); | ||
49 | static char **make_env_array_from_var_list __P((SHELL_VAR **)); | ||
50 | static char **make_var_export_array __P((VAR_CONTEXT *)); | ||
51 | static char **make_func_export_array __P((void)); | ||
52 | @@ -349,22 +354,33 @@ | ||
53 | |||
54 | /* If exported function, define it now. Don't import functions from | ||
55 | the environment in privileged mode. */ | ||
56 | - if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4)) | ||
57 | + if (privmode == 0 && read_but_dont_execute == 0 && | ||
58 | + STREQN (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) && | ||
59 | + STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) && | ||
60 | + STREQN ("() {", string, 4)) | ||
61 | { | ||
62 | + size_t namelen; | ||
63 | + char *tname; /* desired imported function name */ | ||
64 | + | ||
65 | + namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN; | ||
66 | + | ||
67 | + tname = name + BASHFUNC_PREFLEN; /* start of func name */ | ||
68 | + tname[namelen] = '\0'; /* now tname == func name */ | ||
69 | + | ||
70 | string_length = strlen (string); | ||
71 | - temp_string = (char *)xmalloc (3 + string_length + char_index); | ||
72 | + temp_string = (char *)xmalloc (namelen + string_length + 2); | ||
73 | |||
74 | - strcpy (temp_string, name); | ||
75 | - temp_string[char_index] = ' '; | ||
76 | - strcpy (temp_string + char_index + 1, string); | ||
77 | + memcpy (temp_string, tname, namelen); | ||
78 | + temp_string[namelen] = ' '; | ||
79 | + memcpy (temp_string + namelen + 1, string, string_length + 1); | ||
80 | |||
81 | /* Don't import function names that are invalid identifiers from the | ||
82 | environment, though we still allow them to be defined as shell | ||
83 | variables. */ | ||
84 | - if (legal_identifier (name)) | ||
85 | - parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
86 | + if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname))) | ||
87 | + parse_and_execute (temp_string, tname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
88 | |||
89 | - if (temp_var = find_function (name)) | ||
90 | + if (temp_var = find_function (tname)) | ||
91 | { | ||
92 | VSETATTR (temp_var, (att_exported|att_imported)); | ||
93 | array_needs_making = 1; | ||
94 | @@ -377,8 +393,11 @@ | ||
95 | array_needs_making = 1; | ||
96 | } | ||
97 | last_command_exit_value = 1; | ||
98 | - report_error (_("error importing function definition for `%s'"), name); | ||
99 | + report_error (_("error importing function definition for `%s'"), tname); | ||
100 | } | ||
101 | + | ||
102 | + /* Restore original suffix */ | ||
103 | + tname[namelen] = BASHFUNC_SUFFIX[0]; | ||
104 | } | ||
105 | #if defined (ARRAY_VARS) | ||
106 | # if ARRAY_EXPORT | ||
107 | @@ -2957,7 +2976,7 @@ | ||
108 | var->context = variable_context; /* XXX */ | ||
109 | |||
110 | INVALIDATE_EXPORTSTR (var); | ||
111 | - var->exportstr = mk_env_string (name, value); | ||
112 | + var->exportstr = mk_env_string (name, value, 0); | ||
113 | |||
114 | array_needs_making = 1; | ||
115 | |||
116 | @@ -3855,21 +3874,42 @@ | ||
117 | /* **************************************************************** */ | ||
118 | |||
119 | static inline char * | ||
120 | -mk_env_string (name, value) | ||
121 | +mk_env_string (name, value, isfunc) | ||
122 | const char *name, *value; | ||
123 | + int isfunc; | ||
124 | { | ||
125 | - int name_len, value_len; | ||
126 | - char *p; | ||
127 | + size_t name_len, value_len; | ||
128 | + char *p, *q; | ||
129 | |||
130 | name_len = strlen (name); | ||
131 | value_len = STRLEN (value); | ||
132 | - p = (char *)xmalloc (2 + name_len + value_len); | ||
133 | - strcpy (p, name); | ||
134 | - p[name_len] = '='; | ||
135 | + | ||
136 | + /* If we are exporting a shell function, construct the encoded function | ||
137 | + name. */ | ||
138 | + if (isfunc && value) | ||
139 | + { | ||
140 | + p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + value_len + 2); | ||
141 | + q = p; | ||
142 | + memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN); | ||
143 | + q += BASHFUNC_PREFLEN; | ||
144 | + memcpy (q, name, name_len); | ||
145 | + q += name_len; | ||
146 | + memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN); | ||
147 | + q += BASHFUNC_SUFFLEN; | ||
148 | + } | ||
149 | + else | ||
150 | + { | ||
151 | + p = (char *)xmalloc (2 + name_len + value_len); | ||
152 | + memcpy (p, name, name_len); | ||
153 | + q = p + name_len; | ||
154 | + } | ||
155 | + | ||
156 | + q[0] = '='; | ||
157 | if (value && *value) | ||
158 | - strcpy (p + name_len + 1, value); | ||
159 | + memcpy (q + 1, value, value_len + 1); | ||
160 | else | ||
161 | - p[name_len + 1] = '\0'; | ||
162 | + q[1] = '\0'; | ||
163 | + | ||
164 | return (p); | ||
165 | } | ||
166 | |||
167 | @@ -3955,7 +3995,7 @@ | ||
168 | /* Gee, I'd like to get away with not using savestring() if we're | ||
169 | using the cached exportstr... */ | ||
170 | list[list_index] = USE_EXPORTSTR ? savestring (value) | ||
171 | - : mk_env_string (var->name, value); | ||
172 | + : mk_env_string (var->name, value, function_p (var)); | ||
173 | |||
174 | if (USE_EXPORTSTR == 0) | ||
175 | SAVE_EXPORTSTR (var, list[list_index]); | ||