From owner-svn-src-stable@freebsd.org Sat Aug 15 19:58:02 2015 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1E629BA19C; Sat, 15 Aug 2015 19:58:01 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E29261961; Sat, 15 Aug 2015 19:58:01 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7FJw1Ds037320; Sat, 15 Aug 2015 19:58:01 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7FJw19O037318; Sat, 15 Aug 2015 19:58:01 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201508151958.t7FJw19O037318@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sat, 15 Aug 2015 19:58:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r286813 - stable/10/bin/sh X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Aug 2015 19:58:02 -0000 Author: jilles Date: Sat Aug 15 19:58:00 2015 New Revision: 286813 URL: https://svnweb.freebsd.org/changeset/base/286813 Log: MFC r284779: sh: Fix some arithmetic undefined behaviour. Fix shifts of possibly negative numbers found with ubsan and avoid signed integer overflow when hashing an extremely long command name. Modified: stable/10/bin/sh/alias.c stable/10/bin/sh/exec.c Directory Properties: stable/10/ (props changed) Modified: stable/10/bin/sh/alias.c ============================================================================== --- stable/10/bin/sh/alias.c Sat Aug 15 19:00:38 2015 (r286812) +++ stable/10/bin/sh/alias.c Sat Aug 15 19:58:00 2015 (r286813) @@ -248,7 +248,7 @@ hashalias(const char *p) { unsigned int hashval; - hashval = *p << 4; + hashval = (unsigned char)*p << 4; while (*p) hashval+= *p++; return &atab[hashval % ATABSIZE]; Modified: stable/10/bin/sh/exec.c ============================================================================== --- stable/10/bin/sh/exec.c Sat Aug 15 19:00:38 2015 (r286812) +++ stable/10/bin/sh/exec.c Sat Aug 15 19:58:00 2015 (r286813) @@ -524,17 +524,16 @@ static struct tblentry **lastcmdentry; static struct tblentry * cmdlookup(const char *name, int add) { - int hashval; + unsigned int hashval; const char *p; struct tblentry *cmdp; struct tblentry **pp; size_t len; p = name; - hashval = *p << 4; + hashval = (unsigned char)*p << 4; while (*p) hashval += *p++; - hashval &= 0x7FFF; pp = &cmdtable[hashval % CMDTABLESIZE]; for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) { if (equal(cmdp->cmdname, name))