Skip to content

Commit

Permalink
Avoid creating an out-of-bounds pointer in word() (#48)
Browse files Browse the repository at this point in the history
As it is never dereferenced in the n == -1 case it shouldn't cause any
problems. However, UBSAN complains about this, so it is required to run
the tests when compiling with -fsanitize=undefined.
  • Loading branch information
arichardson authored and arnoldrobbins committed Sep 10, 2019
1 parent cbf9243 commit ad9bd2f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lex.c
Expand Up @@ -461,9 +461,8 @@ int word(char *w)
int c, n;

n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
kp = keywords + n;
if (n != -1) { /* found in table */
kp = keywords + n;
yylval.i = kp->sub;
switch (kp->type) { /* special handling */
case BLTIN:
Expand Down

0 comments on commit ad9bd2f

Please sign in to comment.