Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/historical/nawk/dist Do not use index out of bounds...



details:   https://anonhg.NetBSD.org/src/rev/3c9c77b65269
branches:  trunk
changeset: 319805:3c9c77b65269
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Jun 12 13:24:28 2018 +0000

description:
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>

diffstat:

 external/historical/nawk/dist/lex.c |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (15 lines):

diff -r 6f60ff780c00 -r 3c9c77b65269 external/historical/nawk/dist/lex.c
--- a/external/historical/nawk/dist/lex.c       Tue Jun 12 13:18:48 2018 +0000
+++ b/external/historical/nawk/dist/lex.c       Tue Jun 12 13:24:28 2018 +0000
@@ -472,9 +472,9 @@
        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:



Home | Main Index | Thread Index | Old Index