summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2015-08-15 19:58:00 +0000
committerjilles <jilles@FreeBSD.org>2015-08-15 19:58:00 +0000
commitaa479658a049405386de079557d4fa41c437ce0b (patch)
treedd5862d98503bfa59b68194f4aa8a661be0b2e4e /bin
parenta91e3ef58a004aace2995a6dec20856019ce1c7d (diff)
downloadFreeBSD-src-aa479658a049405386de079557d4fa41c437ce0b.zip
FreeBSD-src-aa479658a049405386de079557d4fa41c437ce0b.tar.gz
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/alias.c2
-rw-r--r--bin/sh/exec.c5
2 files changed, 3 insertions, 4 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c
index 21f3f44..a77ce99 100644
--- a/bin/sh/alias.c
+++ b/bin/sh/alias.c
@@ -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];
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index e547e31..d245b55 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -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))
OpenPOWER on IntegriCloud