tn3399_openwrt/package/utils/busybox/patches/250-ash_export-n.patch
Felix Fietkau 33ae9569a4 busybox: fix existing "export -n" in ash
Minor fix to existing patch which did not correctly implement -n support for the export command in ash. The VEXPORT flag of a variable was set in the first call to setvareq() and then remained set in the subsequent call, because the variable already existed in the environment.

Although /lib/functions.sh by default does not export variables (NO_EXPORT=1), this issue was leading to dirty environments.

Without this fix:
(ash) export A=1; export -n B=2; /bin/ash -c "echo \$A, \$B"
1, 2

With this fix:
(ash) export A=1; export -n B=2; /bin/ash -c "echo \$A, \$B"
1,

Signed-off-by: Christophe Lermytte <openwrt@lermytte.be>

SVN-Revision: 39968
2014-03-20 14:14:30 +00:00

35 lines
766 B
Diff

--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12611,8 +12611,17 @@ exportcmd(int argc UNUSED_PARAM, char **
const char *p;
char **aptr;
int flag = argv[0][0] == 'r' ? VREADONLY : VEXPORT;
+ int mask = ~0;
+ int nopt;
+ while ((nopt = nextopt("np"))) {
+ if (nopt == 'n') {
+ mask = ~flag;
+ } else { /* p */
+ break;
+ }
+ }
- if (nextopt("p") != 'p') {
+ if (nopt != 'p') {
aptr = argptr;
name = *aptr;
if (name) {
@@ -12624,10 +12633,11 @@ exportcmd(int argc UNUSED_PARAM, char **
vp = *findvar(hashvar(name), name);
if (vp) {
vp->flags |= flag;
+ vp->flags &= mask;
continue;
}
}
- setvar(name, p, flag);
+ setvar(name, p, flag & mask);
} while ((name = *++aptr) != NULL);
return 0;
}