Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/su Amazing how this worked for so long. setenv(3) ex...



details:   https://anonhg.NetBSD.org/src/rev/1c63374bf5ab
branches:  trunk
changeset: 475880:1c63374bf5ab
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Aug 29 04:21:55 1999 +0000

description:
Amazing how this worked for so long. setenv(3) expects environ(7) to be
a malloc'ed pointer and it tries to realloc(3) it if it had to grow it
before. su(1) gave it a pointer from the stack which caused realloc to
core dump.

diffstat:

 usr.bin/su/su.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (48 lines):

diff -r f15bd42f7ddf -r 1c63374bf5ab usr.bin/su/su.c
--- a/usr.bin/su/su.c   Sun Aug 29 00:30:08 1999 +0000
+++ b/usr.bin/su/su.c   Sun Aug 29 04:21:55 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: su.c,v 1.34 1999/07/11 23:41:10 kim Exp $      */
+/*     $NetBSD: su.c,v 1.35 1999/08/29 04:21:55 christos Exp $ */
 
 /*
  * Copyright (c) 1988 The Regents of the University of California.
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)su.c       8.3 (Berkeley) 4/2/94";*/
 #else
-__RCSID("$NetBSD: su.c,v 1.34 1999/07/11 23:41:10 kim Exp $");
+__RCSID("$NetBSD: su.c,v 1.35 1999/08/29 04:21:55 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -109,7 +109,7 @@
        uid_t ruid;
        int asme, ch, asthem, fastlogin, prio;
        enum { UNSET, YES, NO } iscsh = UNSET;
-       char *user, *shell, *avshell, *username, *cleanenv[10], **np;
+       char *user, *shell, *avshell, *username, **np;
        char *userpass;
        char shellbuf[MAXPATHLEN], avshellbuf[MAXPATHLEN];
 
@@ -179,7 +179,6 @@
 
        if ((pwd = getpwnam(user)) == NULL)
                errx(1, "unknown login %s", user);
-
        if (ruid
 #ifdef KERBEROS
            && (!use_kerberos || kerberos(username, user, pwd->pw_uid))
@@ -292,8 +291,10 @@
        if (!asme) {
                if (asthem) {
                        p = getenv("TERM");
-                       cleanenv[0] = NULL;
-                       environ = cleanenv;
+                       /* Create an empty environment */
+                       if ((environ = malloc(sizeof(char *))) == NULL)
+                               err(1, "%s", "");
+                       environ[0] = NULL;
                        (void)setenv("PATH", _PATH_DEFPATH, 1);
                        if (p)
                                (void)setenv("TERM", p, 1);



Home | Main Index | Thread Index | Old Index