Browse code

exec: use proper header field iterator to print env variables

- issue introduced with the patch for shellshock
- reported by and credits for troubleshooting to Kristian Kielhofner

(cherry picked from commit 8855e3e7fcece4ca2ab33e1f9c54b15831152400)

Daniel-Constantin Mierla authored on 05/12/2014 21:40:25
Showing 1 changed files
... ...
@@ -258,21 +258,23 @@ static int print_hf_var(struct hf_wrapper *w, int offset)
258 258
 	memcpy(envvar, w->prefix, w->prefix_len); c=envvar+w->prefix_len;
259 259
 	memcpy(c, hname, hlen ); c+=hlen;
260 260
 	*c=EV_ASSIGN;c++;
261
-	if (exec_bash_safety && !strncmp(w->u.hf->body.s,"() {",MIN(w->u.hf->body.len,4))) {
261
+	if (exec_bash_safety && !strncmp(w->u.hf->body.s, "() {",
262
+				MIN(w->u.hf->body.len,4))) {
262 263
 		memcpy(c, w->u.hf->body.s+offset+2, w->u.hf->body.len-2 );
263 264
 		c+=(w->u.hf->body.len-2);
264 265
 	} else {
265 266
 		memcpy(c, w->u.hf->body.s+offset, w->u.hf->body.len );
266 267
 		c+=w->u.hf->body.len;
267 268
 	}
268
-	for (wi=w->next_same; wi; wi=wi->next_same) {
269
+	for(wi=w->next_same; wi; wi=wi->next_same) {
269 270
 		*c=HF_SEPARATOR;c++;
270
-		if (exec_bash_safety && !strncmp(w->u.hf->body.s,"() {",MIN(w->u.hf->body.len,4))) {
271
-			memcpy(c, w->u.hf->body.s+offset+2, w->u.hf->body.len-2 );
272
-			c+=(w->u.hf->body.len-2);
271
+		if (exec_bash_safety && !strncmp(wi->u.hf->body.s, "() {",
272
+					MIN(w->u.hf->body.len,4))) {
273
+			memcpy(c, wi->u.hf->body.s+offset+2, wi->u.hf->body.len-2 );
274
+			c+=(wi->u.hf->body.len-2);
273 275
 		} else {
274
-			memcpy(c, w->u.hf->body.s+offset, w->u.hf->body.len );
275
-			c+=w->u.hf->body.len;
276
+			memcpy(c, wi->u.hf->body.s+offset, wi->u.hf->body.len );
277
+			c+=wi->u.hf->body.len;
276 278
 		}
277 279
 	}
278 280
 	*c=0; /* zero termination */