From 453ce8642b69943dee03e89fb7666a80f7c84bcf Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 29 Jul 2020 12:31:29 -0600 Subject: 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. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') 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; } -- cgit v1.2.3