From owner-svn-src-all@FreeBSD.ORG Sat Nov 3 22:23:09 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8D38BB1B; Sat, 3 Nov 2012 22:23:09 +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 739968FC14; Sat, 3 Nov 2012 22:23:09 +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 qA3MN9pv056536; Sat, 3 Nov 2012 22:23:09 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id qA3MN9wh056534; Sat, 3 Nov 2012 22:23:09 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201211032223.qA3MN9wh056534@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 3 Nov 2012 22:23:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242530 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Nov 2012 22:23:09 -0000 Author: jilles Date: Sat Nov 3 22:23:08 2012 New Revision: 242530 URL: http://svn.freebsd.org/changeset/base/242530 Log: sh: Use C99 flexible array instead of accessing array beyond bounds. Although sufficient memory is available for a longer string in cmdname, this is undefined behaviour anyway. Side effect: for alignment reasons, an additional byte of memory is allocated per hashed command. Modified: head/bin/sh/exec.c Modified: head/bin/sh/exec.c ============================================================================== --- head/bin/sh/exec.c Sat Nov 3 22:21:37 2012 (r242529) +++ head/bin/sh/exec.c Sat Nov 3 22:23:08 2012 (r242530) @@ -78,7 +78,6 @@ __FBSDID("$FreeBSD$"); #define CMDTABLESIZE 31 /* should be prime */ -#define ARB 1 /* actual size determined at run time */ @@ -88,7 +87,7 @@ struct tblentry { int special; /* flag for special builtin commands */ short cmdtype; /* index identifying command */ char rehash; /* if set, cd done since entry created */ - char cmdname[ARB]; /* name of command */ + char cmdname[]; /* name of command */ }; @@ -563,7 +562,7 @@ cmdlookup(const char *name, int add) } if (add && cmdp == NULL) { INTOFF; - cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB + cmdp = *pp = ckmalloc(sizeof (struct tblentry) + strlen(name) + 1); cmdp->next = NULL; cmdp->cmdtype = CMDUNKNOWN;