cvs commit: src/bin/df df.c src/bin/sh var.c src/include stdlib.h src/libexec/pppoed pppoed.c src/sys/sys param.h src/lib/libc/stdlib Makefile.inc getenv.3 getenv.c putenv.c setenv.c src/tools/regression/environ Makefile Makefile.envctl ...

Andrey Chernov ache at nagual.pp.ru
Wed Jul 4 15:01:27 UTC 2007


On Wed, Jul 04, 2007 at 06:42:49PM +0400, Andrey Chernov wrote:
> On Wed, Jul 04, 2007 at 12:00:41AM +0000, Sean Farley wrote:
> >   Several patches to base utilities to handle the POSIX changes from
> >   Andrey Chernov's previous commit.  A few I re-wrote to use setenv()
> >   instead of putenv().
> 
> Replacing putenv() with setenv() should care about the case when putenv() 
> uses getenv()-provided value directly, like in sh's var.c. It should be 
> copied by strdup() or something like first to not break env before 
> following setenv() call. 
> 
> In my patch I always care about this.

Here is a patch which fix that and unsetenv("foo=bar") problem too.

Index: var.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/var.c,v
retrieving revision 1.36
diff -u -r1.36 var.c
--- var.c	4 Jul 2007 00:00:38 -0000	1.36
+++ var.c	4 Jul 2007 14:59:19 -0000
@@ -289,7 +289,7 @@
 setvareq(char *s, int flags)
 {
 	struct var *vp, **vpp;
-	char *p;
+	char *p, *ss;
 	int len;
 
 	if (aflag)
@@ -320,10 +320,11 @@
 			if (vp == &vmpath || (vp == &vmail && ! mpathset()))
 				chkmail(1);
 			if ((vp->flags & VEXPORT) && localevar(s)) {
-				p = strchr(s, '=');
+				ss = savestr(s);
+				p = strchr(ss, '=');
 				*p = '\0';
-				(void) setenv(s, p + 1, 1);
-				*p = '=';
+				(void) setenv(ss, p + 1, 1);
+				ckfree(ss);
 				(void) setlocale(LC_ALL, "");
 			}
 			INTON;
@@ -339,10 +340,11 @@
 	INTOFF;
 	*vpp = vp;
 	if ((vp->flags & VEXPORT) && localevar(s)) {
-		p = strchr(s, '=');
+		ss = savestr(s);
+		p = strchr(ss, '=');
 		*p = '\0';
-		(void) setenv(s, p + 1, 1);
-		*p = '=';
+		(void) setenv(ss, p + 1, 1);
+		ckfree(ss);
 		(void) setlocale(LC_ALL, "");
 	}
 	INTON;
@@ -567,7 +569,7 @@
 	struct var **vpp;
 	struct var *vp;
 	char *name;
-	char *p;
+	char *p, *ss;
 	char *cmdname;
 	int ch, values;
 	int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
@@ -603,10 +605,11 @@
 
 						vp->flags |= flag;
 						if ((vp->flags & VEXPORT) && localevar(vp->text)) {
-							p = strchr(vp->text, '=');
+							ss = savestr(vp->text);
+							p = strchr(ss, '=');
 							*p = '\0';
-							(void) setenv(vp->text, p + 1, 1);
-							*p = '=';
+							(void) setenv(ss, p + 1, 1);
+							ckfree(ss);
 							(void) setlocale(LC_ALL, "");
 						}
 						goto found;
@@ -788,6 +791,7 @@
 {
 	struct var **vpp;
 	struct var *vp;
+	char *ss, *eqp;
 
 	vpp = hashvar(s);
 	for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) {
@@ -798,7 +802,11 @@
 			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;

-- 
http://ache.pp.ru/


More information about the cvs-src mailing list