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)) _______________________________________________ svn-src-stable-10@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10 To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"