[PATCH] setenv|putenv rc checking (lib)

Simon 'corecode' Schubert corecode at fs.ei.tum.de
Thu Sep 29 05:13:16 PDT 2005


Alexey Slynko wrote:
------------------------------------------------------------------------

Index: libutil/login_class.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/lib/libutil/login_class.c,v
retrieving revision 1.4
diff -u -r1.4 login_class.c
--- libutil/login_class.c	4 Mar 2005 04:31:11 -0000	1.4
+++ libutil/login_class.c	29 Sep 2005 01:22:16 -0000
@@ -31,6 +31,7 @@
 #include <sys/resource.h>
 #include <sys/rtprio.h>
 
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -210,10 +211,12 @@
 	char * np  = substvar(var, pwd, hlen, pch, nlen);
 
 	if (np != NULL) {
-	    setenv(vars->var, np, vars->overwrite);
+	    if (setenv(vars->var, np, vars->overwrite) == ENOMEM)
+		err(1, "setenv: cannot set %s=%s", vars->var, np);
 	    free(np);
 	} else if (vars->def != NULL) {
-	    setenv(vars->var, vars->def, 0);
+	    if (setenv(vars->var, vars->def, 0) == ENOMEM)
+		err(1, "setenv: cannot set %s=%s", vars->var, vars->def);
 	}
 	++vars;
     }
@@ -234,7 +237,8 @@
 
 		    *p++ = '\0';
 		    if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) {
-			setenv(*set_env, np, 1);
+			if (setenv(*set_env, np, 1) == ENOMEM)
+				err(1, "setenv: cannot set %s=%s", *set_env, np);
 			free(np);
 		    }
 		}
worth discussing if we should fail or just warn.  I'd say warn is enough 
because the user can change his env anyways.

--
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low $$$ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \




More information about the Submit mailing list