From owner-svn-src-stable-8@FreeBSD.ORG Sun May 29 15:07:53 2011 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDE6E1065672; Sun, 29 May 2011 15:07:53 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BDC538FC0A; Sun, 29 May 2011 15:07:53 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4TF7rjs035262; Sun, 29 May 2011 15:07:53 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4TF7rC7035260; Sun, 29 May 2011 15:07:53 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201105291507.p4TF7rC7035260@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 29 May 2011 15:07:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222452 - stable/8/bin/sh X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 May 2011 15:07:53 -0000 Author: jilles Date: Sun May 29 15:07:53 2011 New Revision: 222452 URL: http://svn.freebsd.org/changeset/base/222452 Log: MFC r222173: sh: Fix bss-based buffer overflow in . builtin. If the length of a directory in PATH together with the given filename exceeded FILENAME_MAX (which may happen even for pathnames that work), a static buffer was overflown. The static buffer is unnecessary, we can use the stalloc() stack. Obtained from: NetBSD Modified: stable/8/bin/sh/main.c Directory Properties: stable/8/bin/sh/ (props changed) Modified: stable/8/bin/sh/main.c ============================================================================== --- stable/8/bin/sh/main.c Sun May 29 15:02:10 2011 (r222451) +++ stable/8/bin/sh/main.c Sun May 29 15:07:53 2011 (r222452) @@ -296,7 +296,6 @@ readcmdfile(const char *name) static char * find_dot_file(char *basename) { - static char localname[FILENAME_MAX+1]; char *fullname; const char *path = pathval(); struct stat statb; @@ -306,10 +305,14 @@ find_dot_file(char *basename) return basename; while ((fullname = padvance(&path, basename)) != NULL) { - strcpy(localname, fullname); + if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { + /* + * Don't bother freeing here, since it will + * be freed by the caller. + */ + return fullname; + } stunalloc(fullname); - if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) - return localname; } return basename; }