diff options
author | Todd C. Miller <Todd.Miller@sudo.ws> | 2020-07-29 12:31:29 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-29 21:31:29 +0300 |
commit | 453ce8642b69943dee03e89fb7666a80f7c84bcf (patch) | |
tree | 901f4efb808fbae87fbd676823d190e14cb28b1c /main.c | |
parent | e22bb7c625df14ad8c9195124ed99cc41d7dfcd2 (diff) | |
download | one-true-awk-453ce8642b69943dee03e89fb7666a80f7c84bcf.tar.gz |
Avoid accessing pfile[] out of bounds on syntax error at EOF. (#90)
When awk reaches EOF parsing the program file, curpfile is incremented.
However, cursource() uses curpfile without checking it against npfile
which can cause an out of bounds access of pfile[] if there is a syntax
error at the end of the program file.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -256,7 +256,7 @@ int pgetc(void) /* get 1 character from awk program */ char *cursource(void) /* current source file name */ { if (npfile > 0) - return pfile[curpfile]; + return pfile[curpfile < npfile ? curpfile : curpfile - 1]; else return NULL; } |