shithub: trueawk

Download patch

ref: 453ce8642b69943dee03e89fb7666a80f7c84bcf
parent: e22bb7c625df14ad8c9195124ed99cc41d7dfcd2
author: Todd C. Miller <Todd.Miller@sudo.ws>
date: Wed Jul 29 08:31:29 EDT 2020

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.

--- /dev/null
+++ b/bugs-fixed/pfile-overflow.awk
@@ -1,0 +1,1 @@
+\
\ No newline at end of file
--- /dev/null
+++ b/bugs-fixed/pfile-overflow.ok
@@ -1,0 +1,4 @@
+../a.out: syntax error at source line 1 source file pfile-overflow.awk
+ context is
+	 >>>  <<< 
+../a.out: bailing out at source line 1 source file pfile-overflow.awk
--- a/main.c
+++ b/main.c
@@ -256,7 +256,7 @@
 char *cursource(void)	/* current source file name */
 {
 	if (npfile > 0)
-		return pfile[curpfile];
+		return pfile[curpfile < npfile ? curpfile : curpfile - 1];
 	else
 		return NULL;
 }
--