From owner-svn-src-head@FreeBSD.ORG Mon Feb 16 21:56:18 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0BF75106566B; Mon, 16 Feb 2009 21:56:18 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E91418FC14; Mon, 16 Feb 2009 21:56:17 +0000 (UTC) (envelope-from cperciva@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1GLuH1S095730; Mon, 16 Feb 2009 21:56:17 GMT (envelope-from cperciva@svn.freebsd.org) Received: (from cperciva@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1GLuHVX095729; Mon, 16 Feb 2009 21:56:17 GMT (envelope-from cperciva@svn.freebsd.org) Message-Id: <200902162156.n1GLuHVX095729@svn.freebsd.org> From: Colin Percival Date: Mon, 16 Feb 2009 21:56:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188699 - head/contrib/telnet/telnetd releng/7.0 releng/7.0/contrib/telnet/telnetd releng/7.0/sys/conf releng/7.1 releng/7.1/contrib/telnet/telnetd releng/7.1/sys/conf stable/7/contrib/... X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Feb 2009 21:56:20 -0000 Author: cperciva Date: Mon Feb 16 21:56:17 2009 New Revision: 188699 URL: http://svn.freebsd.org/changeset/base/188699 Log: Correctly scrub telnetd's environment. Approved by: so (cperciva) Security: FreeBSD-SA-09:05.telnetd Modified: head/contrib/telnet/telnetd/sys_term.c Changes in other areas also in this revision: Modified: releng/7.0/UPDATING releng/7.0/contrib/telnet/telnetd/sys_term.c releng/7.0/sys/conf/newvers.sh releng/7.1/UPDATING releng/7.1/contrib/telnet/telnetd/sys_term.c releng/7.1/sys/conf/newvers.sh stable/7/contrib/telnet/telnetd/sys_term.c Modified: head/contrib/telnet/telnetd/sys_term.c ============================================================================== --- head/contrib/telnet/telnetd/sys_term.c Mon Feb 16 21:42:41 2009 (r188698) +++ head/contrib/telnet/telnetd/sys_term.c Mon Feb 16 21:56:17 2009 (r188699) @@ -1271,8 +1271,18 @@ scrub_env(void) 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++) @@ -1286,10 +1296,15 @@ scrub_env(void) 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; } /*