From owner-svn-src-all@freebsd.org Wed Jun 24 20:51:49 2015 Return-Path: Delivered-To: svn-src-all@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 7A5F1915ED7; Wed, 24 Jun 2015 20:51:49 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.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 6C09F1142; Wed, 24 Jun 2015 20:51:49 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5OKpn2H075256; Wed, 24 Jun 2015 20:51:49 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5OKpnhx074912; Wed, 24 Jun 2015 20:51:49 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201506242051.t5OKpnhx074912@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Wed, 24 Jun 2015 20:51:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284779 - 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.20 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: Wed, 24 Jun 2015 20:51:49 -0000 Author: jilles Date: Wed Jun 24 20:51:48 2015 New Revision: 284779 URL: https://svnweb.freebsd.org/changeset/base/284779 Log: 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. MFC after: 1 week Modified: head/bin/sh/alias.c head/bin/sh/exec.c Modified: head/bin/sh/alias.c ============================================================================== --- head/bin/sh/alias.c Wed Jun 24 19:58:14 2015 (r284778) +++ head/bin/sh/alias.c Wed Jun 24 20:51:48 2015 (r284779) @@ -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: head/bin/sh/exec.c ============================================================================== --- head/bin/sh/exec.c Wed Jun 24 19:58:14 2015 (r284778) +++ head/bin/sh/exec.c Wed Jun 24 20:51:48 2015 (r284779) @@ -522,17 +522,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))