Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix buffer overflow due to incorrect nv_endsubscript() calls
The nv_endsubscript() function finds the end of an array subscript and returns a pointer to the character following it. But this only works correctly if the 'cp' pointer passed points to the initial '[' of the subscript, not to any subsequente character. Otherwise, backslash quotes may mess it up and a pointer past the character following the subscript may be returned, causing potential buffer overflows. (This manifested in some regression test failures in tests/nameref.sh when run with a ksh compiled with ASan.) These fixes were found by adding an assert(*cp=='[') at the beginning of nv_subscript() and running the regression tests. src/cmd/ksh93/sh/arith.c, src/cmd/ksh93/sh/name.c: - Correct two erroneous nv_subscript() calls found by that assert by adjusting the cp parameter to point to the initial '['.
- Loading branch information