Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jun 2015 20:51:48 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r284779 - head/bin/sh
Message-ID:  <201506242051.t5OKpnhx074912@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201506242051.t5OKpnhx074912>