code: plan9front

Download patch

ref: 26e42d115979009c9fe144e1c28f740485537674
parent: 9ab4f2a2428ef5ad2f4abc118f589bd70f6c2f90
author: Jacob Moody <moody@posixcafe.org>
date: Wed Apr 5 22:59:11 EDT 2023

awk: getline: do not access unitialized data on EOF

echo 'a' | awk 'BEGIN { getline l; getline l; print (s=substr(l,1,10)) " len=" length(s) }'
https://github.com/onetrueawk/awk/commit/1debe1993fc852545a9215621d884be27f08a223

--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -438,10 +438,12 @@
 			n = getrec(&record, &recsize, 1);
 		else {			/* getline var */
 			n = getrec(&buf, &bufsize, 0);
-			x = execute(a[0]);
-			setsval(x, buf);
-			if (istemp(x))
-				tfree(x);
+			if (n > 0) {
+				x = execute(a[0]);
+				setsval(x, buf);
+				if (istemp(x))
+					tfree(x);
+			}
 		}
 	}
 	setfval(r, (Awkfloat) n);