aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2020-07-29 12:31:29 -0600
committerGitHub <noreply@github.com>2020-07-29 21:31:29 +0300
commit453ce8642b69943dee03e89fb7666a80f7c84bcf (patch)
tree901f4efb808fbae87fbd676823d190e14cb28b1c /main.c
parente22bb7c625df14ad8c9195124ed99cc41d7dfcd2 (diff)
downloadone-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.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/main.c b/main.c
index 535f1aa..a3e0022 100644
--- a/main.c
+++ b/main.c
@@ -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;
}