Module Name:    src
Committed By:   kamil
Date:           Tue Jun 12 13:24:28 UTC 2018

Modified Files:
        src/external/historical/nawk/dist: lex.c

Log Message:
Do not use index out of bounds in nawk

$ awk '{w=$1}' < /dev/null
/public/src.git/external/historical/nawk/bin/../dist/lex.c:476:16: runtime 
error: index -1 out of bounds for type 'const Keyword [46]'

There used to be documented a bug in the code that index ouf of bounds
can in theory fault (by daniel barrett).

Before assigning the pointer, first check for the index whether it's not
not -1. This was a suggested solution in the comment in the code.

The sanitizer is overcautious as this pointer wasn't dereferenced, but
fix is nonetheless.

Sponsored by <The NetBSD Foundation>


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/historical/nawk/dist/lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/historical/nawk/dist/lex.c
diff -u src/external/historical/nawk/dist/lex.c:1.3 src/external/historical/nawk/dist/lex.c:1.4
--- src/external/historical/nawk/dist/lex.c:1.3	Fri Sep  1 07:01:06 2017
+++ src/external/historical/nawk/dist/lex.c	Tue Jun 12 13:24:28 2018
@@ -472,9 +472,9 @@ 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:

Reply via email to