diff options
author | ache <ache@FreeBSD.org> | 2007-04-30 11:44:42 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2007-04-30 11:44:42 +0000 |
commit | ac682a1ec200e43e37b2f788e0e44503baf4665e (patch) | |
tree | 9a99b0f1a1d6b209300573fba5fa4221f813fe1a /bin | |
parent | 3f3de6c76718e1fffd0c7e4c72e9a5c0126e2658 (diff) | |
download | FreeBSD-src-ac682a1ec200e43e37b2f788e0e44503baf4665e.zip FreeBSD-src-ac682a1ec200e43e37b2f788e0e44503baf4665e.tar.gz |
Put some safeguards:
1) Under POSIX unsetenv("foo=bar") is explicit error and not equal
to unsetenv("foo")
2) Prepare for upcomig POSIXed putenv() rewrite: make putenv() calls
portable and conforming to standard.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/var.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/sh/var.c b/bin/sh/var.c index 54a0a84..b86ecfb 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -319,7 +319,7 @@ setvareq(char *s, int flags) if (vp == &vmpath || (vp == &vmail && ! mpathset())) chkmail(1); if ((vp->flags & VEXPORT) && localevar(s)) { - putenv(s); + (void) putenv((vp->flags & VTEXTFIXED) ? vp->text : savestr(vp->text)); (void) setlocale(LC_ALL, ""); } INTON; @@ -335,7 +335,7 @@ setvareq(char *s, int flags) INTOFF; *vpp = vp; if ((vp->flags & VEXPORT) && localevar(s)) { - putenv(s); + (void) putenv((vp->flags & VTEXTFIXED) ? vp->text : savestr(vp->text)); (void) setlocale(LC_ALL, ""); } INTON; @@ -596,7 +596,7 @@ exportcmd(int argc, char **argv) vp->flags |= flag; if ((vp->flags & VEXPORT) && localevar(vp->text)) { - putenv(vp->text); + (void) putenv((vp->flags & VTEXTFIXED) ? vp->text : savestr(vp->text)); (void) setlocale(LC_ALL, ""); } goto found; @@ -776,6 +776,7 @@ unsetcmd(int argc __unused, char **argv __unused) int unsetvar(char *s) { + char *eqp, *ss; struct var **vpp; struct var *vp; @@ -788,7 +789,11 @@ unsetvar(char *s) if (*(strchr(vp->text, '=') + 1) != '\0') setvar(s, nullstr, 0); if ((vp->flags & VEXPORT) && localevar(vp->text)) { - unsetenv(s); + ss = savestr(s); + if ((eqp = strchr(ss, '=')) != NULL) + *eqp = '\0'; + (void) unsetenv(ss); + ckfree(ss); setlocale(LC_ALL, ""); } vp->flags &= ~VEXPORT; |