diff options
Diffstat (limited to 'meta/recipes-extended/bash/bash-4.2/Fix-for-bash-exported-function-namespace-change.patch')
-rw-r--r-- | meta/recipes-extended/bash/bash-4.2/Fix-for-bash-exported-function-namespace-change.patch | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/meta/recipes-extended/bash/bash-4.2/Fix-for-bash-exported-function-namespace-change.patch b/meta/recipes-extended/bash/bash-4.2/Fix-for-bash-exported-function-namespace-change.patch new file mode 100644 index 0000000000..0fb2ad5d89 --- /dev/null +++ b/meta/recipes-extended/bash/bash-4.2/Fix-for-bash-exported-function-namespace-change.patch | |||
@@ -0,0 +1,212 @@ | |||
1 | Fix for exported function namespace change | ||
2 | |||
3 | Upstream-Status: Backport | ||
4 | |||
5 | Downloaded from: http://ftp.gnu.org/gnu/bash/bash-4.2-patches/bash42-050 | ||
6 | |||
7 | Author: Chet Ramey <chet.ramey@case.edu> | ||
8 | Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> | ||
9 | |||
10 | |||
11 | BASH PATCH REPORT | ||
12 | ================= | ||
13 | |||
14 | Bash-Release: 4.2 | ||
15 | Patch-ID: bash42-050 | ||
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 | Patch (apply with `patch -p0'): | ||
29 | |||
30 | *** ../bash-4.2.49/variables.c 2014-09-16 19:35:45.000000000 -0400 | ||
31 | --- variables.c 2014-09-27 20:54:00.000000000 -0400 | ||
32 | *************** | ||
33 | *** 80,83 **** | ||
34 | --- 80,88 ---- | ||
35 | #define ifsname(s) ((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && (s)[3] == '\0') | ||
36 | |||
37 | + #define BASHFUNC_PREFIX "BASH_FUNC_" | ||
38 | + #define BASHFUNC_PREFLEN 10 /* == strlen(BASHFUNC_PREFIX */ | ||
39 | + #define BASHFUNC_SUFFIX "%%" | ||
40 | + #define BASHFUNC_SUFFLEN 2 /* == strlen(BASHFUNC_SUFFIX) */ | ||
41 | + | ||
42 | extern char **environ; | ||
43 | |||
44 | *************** | ||
45 | *** 269,273 **** | ||
46 | static void dispose_temporary_env __P((sh_free_func_t *)); | ||
47 | |||
48 | ! static inline char *mk_env_string __P((const char *, const char *)); | ||
49 | static char **make_env_array_from_var_list __P((SHELL_VAR **)); | ||
50 | static char **make_var_export_array __P((VAR_CONTEXT *)); | ||
51 | --- 274,278 ---- | ||
52 | static void dispose_temporary_env __P((sh_free_func_t *)); | ||
53 | |||
54 | ! static inline char *mk_env_string __P((const char *, const char *, int)); | ||
55 | static char **make_env_array_from_var_list __P((SHELL_VAR **)); | ||
56 | static char **make_var_export_array __P((VAR_CONTEXT *)); | ||
57 | *************** | ||
58 | *** 339,357 **** | ||
59 | /* If exported function, define it now. Don't import functions from | ||
60 | the environment in privileged mode. */ | ||
61 | ! if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4)) | ||
62 | { | ||
63 | string_length = strlen (string); | ||
64 | ! temp_string = (char *)xmalloc (3 + string_length + char_index); | ||
65 | |||
66 | ! strcpy (temp_string, name); | ||
67 | ! temp_string[char_index] = ' '; | ||
68 | ! strcpy (temp_string + char_index + 1, string); | ||
69 | |||
70 | /* Don't import function names that are invalid identifiers from the | ||
71 | environment. */ | ||
72 | ! if (legal_identifier (name)) | ||
73 | ! parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
74 | |||
75 | ! if (temp_var = find_function (name)) | ||
76 | { | ||
77 | VSETATTR (temp_var, (att_exported|att_imported)); | ||
78 | --- 344,373 ---- | ||
79 | /* If exported function, define it now. Don't import functions from | ||
80 | the environment in privileged mode. */ | ||
81 | ! if (privmode == 0 && read_but_dont_execute == 0 && | ||
82 | ! STREQN (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) && | ||
83 | ! STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) && | ||
84 | ! STREQN ("() {", string, 4)) | ||
85 | { | ||
86 | + size_t namelen; | ||
87 | + char *tname; /* desired imported function name */ | ||
88 | + | ||
89 | + namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN; | ||
90 | + | ||
91 | + tname = name + BASHFUNC_PREFLEN; /* start of func name */ | ||
92 | + tname[namelen] = '\0'; /* now tname == func name */ | ||
93 | + | ||
94 | string_length = strlen (string); | ||
95 | ! temp_string = (char *)xmalloc (namelen + string_length + 2); | ||
96 | |||
97 | ! memcpy (temp_string, tname, namelen); | ||
98 | ! temp_string[namelen] = ' '; | ||
99 | ! memcpy (temp_string + namelen + 1, string, string_length + 1); | ||
100 | |||
101 | /* Don't import function names that are invalid identifiers from the | ||
102 | environment. */ | ||
103 | ! if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname))) | ||
104 | ! parse_and_execute (temp_string, tname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD); | ||
105 | |||
106 | ! if (temp_var = find_function (tname)) | ||
107 | { | ||
108 | VSETATTR (temp_var, (att_exported|att_imported)); | ||
109 | *************** | ||
110 | *** 359,363 **** | ||
111 | } | ||
112 | else | ||
113 | ! report_error (_("error importing function definition for `%s'"), name); | ||
114 | } | ||
115 | #if defined (ARRAY_VARS) | ||
116 | --- 375,382 ---- | ||
117 | } | ||
118 | else | ||
119 | ! report_error (_("error importing function definition for `%s'"), tname); | ||
120 | ! | ||
121 | ! /* Restore original suffix */ | ||
122 | ! tname[namelen] = BASHFUNC_SUFFIX[0]; | ||
123 | } | ||
124 | #if defined (ARRAY_VARS) | ||
125 | *************** | ||
126 | *** 2538,2542 **** | ||
127 | |||
128 | INVALIDATE_EXPORTSTR (var); | ||
129 | ! var->exportstr = mk_env_string (name, value); | ||
130 | |||
131 | array_needs_making = 1; | ||
132 | --- 2557,2561 ---- | ||
133 | |||
134 | INVALIDATE_EXPORTSTR (var); | ||
135 | ! var->exportstr = mk_env_string (name, value, 0); | ||
136 | |||
137 | array_needs_making = 1; | ||
138 | *************** | ||
139 | *** 3390,3408 **** | ||
140 | |||
141 | static inline char * | ||
142 | ! mk_env_string (name, value) | ||
143 | const char *name, *value; | ||
144 | { | ||
145 | ! int name_len, value_len; | ||
146 | ! char *p; | ||
147 | |||
148 | name_len = strlen (name); | ||
149 | value_len = STRLEN (value); | ||
150 | ! p = (char *)xmalloc (2 + name_len + value_len); | ||
151 | ! strcpy (p, name); | ||
152 | ! p[name_len] = '='; | ||
153 | if (value && *value) | ||
154 | ! strcpy (p + name_len + 1, value); | ||
155 | else | ||
156 | ! p[name_len + 1] = '\0'; | ||
157 | return (p); | ||
158 | } | ||
159 | --- 3409,3448 ---- | ||
160 | |||
161 | static inline char * | ||
162 | ! mk_env_string (name, value, isfunc) | ||
163 | const char *name, *value; | ||
164 | + int isfunc; | ||
165 | { | ||
166 | ! size_t name_len, value_len; | ||
167 | ! char *p, *q; | ||
168 | |||
169 | name_len = strlen (name); | ||
170 | value_len = STRLEN (value); | ||
171 | ! | ||
172 | ! /* If we are exporting a shell function, construct the encoded function | ||
173 | ! name. */ | ||
174 | ! if (isfunc && value) | ||
175 | ! { | ||
176 | ! p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + value_len + 2); | ||
177 | ! q = p; | ||
178 | ! memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN); | ||
179 | ! q += BASHFUNC_PREFLEN; | ||
180 | ! memcpy (q, name, name_len); | ||
181 | ! q += name_len; | ||
182 | ! memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN); | ||
183 | ! q += BASHFUNC_SUFFLEN; | ||
184 | ! } | ||
185 | ! else | ||
186 | ! { | ||
187 | ! p = (char *)xmalloc (2 + name_len + value_len); | ||
188 | ! memcpy (p, name, name_len); | ||
189 | ! q = p + name_len; | ||
190 | ! } | ||
191 | ! | ||
192 | ! q[0] = '='; | ||
193 | if (value && *value) | ||
194 | ! memcpy (q + 1, value, value_len + 1); | ||
195 | else | ||
196 | ! q[1] = '\0'; | ||
197 | ! | ||
198 | return (p); | ||
199 | } | ||
200 | *************** | ||
201 | *** 3490,3494 **** | ||
202 | using the cached exportstr... */ | ||
203 | list[list_index] = USE_EXPORTSTR ? savestring (value) | ||
204 | ! : mk_env_string (var->name, value); | ||
205 | |||
206 | if (USE_EXPORTSTR == 0) | ||
207 | --- 3530,3534 ---- | ||
208 | using the cached exportstr... */ | ||
209 | list[list_index] = USE_EXPORTSTR ? savestring (value) | ||
210 | ! : mk_env_string (var->name, value, function_p (var)); | ||
211 | |||
212 | if (USE_EXPORTSTR == 0) | ||