[Midnightbsd-cvs] src: sys_term.c: Due to changes in environment handling, the scrubbing

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Feb 16 17:24:48 EST 2009


Log Message:
-----------
Due to changes in environment handling, the scrubbing is no longer effective.  Correct this defect.

Modified Files:
--------------
    src/contrib/telnet/telnetd:
        sys_term.c (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: sys_term.c
===================================================================
RCS file: /home/cvs/src/contrib/telnet/telnetd/sys_term.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L contrib/telnet/telnetd/sys_term.c -L contrib/telnet/telnetd/sys_term.c -u -r1.1.1.1 -r1.2
--- contrib/telnet/telnetd/sys_term.c
+++ contrib/telnet/telnetd/sys_term.c
@@ -1285,8 +1285,18 @@
 
 	char **cpp, **cpp2;
 	const char **p;
- 
- 	for (cpp2 = cpp = environ; *cpp; cpp++) {
+	char ** new_environ;
+	size_t count;
+
+	/* Allocate space for scrubbed environment. */
+	for (count = 1, cpp = environ; *cpp; count++, cpp++)
+		continue;
+	if ((new_environ = malloc(count * sizeof(char *))) == NULL) {
+		environ = NULL;
+		return;
+	}
+
+ 	for (cpp2 = new_environ, cpp = environ; *cpp; cpp++) {
 		int reject_it = 0;
 
 		for(p = rej; *p; p++)
@@ -1300,10 +1310,15 @@
 		for(p = acc; *p; p++)
 			if(strncmp(*cpp, *p, strlen(*p)) == 0)
 				break;
-		if(*p != NULL)
- 			*cpp2++ = *cpp;
+		if(*p != NULL) {
+			if ((*cpp2++ = strdup(*cpp)) == NULL) {
+				environ = new_environ;
+				return;
+			}
+		}
  	}
 	*cpp2 = NULL;
+	environ = new_environ;
 }
 
 /*


More information about the Midnightbsd-cvs mailing list