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
This commit is contained in:
parent
a5b789f65a
commit
c3c85727d0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=284779
@ -248,7 +248,7 @@ hashalias(const char *p)
|
|||||||
{
|
{
|
||||||
unsigned int hashval;
|
unsigned int hashval;
|
||||||
|
|
||||||
hashval = *p << 4;
|
hashval = (unsigned char)*p << 4;
|
||||||
while (*p)
|
while (*p)
|
||||||
hashval+= *p++;
|
hashval+= *p++;
|
||||||
return &atab[hashval % ATABSIZE];
|
return &atab[hashval % ATABSIZE];
|
||||||
|
@ -522,17 +522,16 @@ static struct tblentry **lastcmdentry;
|
|||||||
static struct tblentry *
|
static struct tblentry *
|
||||||
cmdlookup(const char *name, int add)
|
cmdlookup(const char *name, int add)
|
||||||
{
|
{
|
||||||
int hashval;
|
unsigned int hashval;
|
||||||
const char *p;
|
const char *p;
|
||||||
struct tblentry *cmdp;
|
struct tblentry *cmdp;
|
||||||
struct tblentry **pp;
|
struct tblentry **pp;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
p = name;
|
p = name;
|
||||||
hashval = *p << 4;
|
hashval = (unsigned char)*p << 4;
|
||||||
while (*p)
|
while (*p)
|
||||||
hashval += *p++;
|
hashval += *p++;
|
||||||
hashval &= 0x7FFF;
|
|
||||||
pp = &cmdtable[hashval % CMDTABLESIZE];
|
pp = &cmdtable[hashval % CMDTABLESIZE];
|
||||||
for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
|
for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
|
||||||
if (equal(cmdp->cmdname, name))
|
if (equal(cmdp->cmdname, name))
|
||||||
|
Loading…
Reference in New Issue
Block a user