shithub: riscv

Download patch

ref: 207cd2812f49e786a95184b296e82452fd7bd717
parent: 26c21f9b5d06296d13f40b53de14e22007e189c2
author: Jacob Moody <[email protected]>
date: Tue Jan 23 16:10:41 EST 2024

awk: fix out of bounds write with large fields (thanks kristo)

; dd < /dev/zero -bs 4 -count 8k | tr '\x0' A | awk '{a=$1}'

Solution copied from onetrueawk.

--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -261,7 +261,7 @@
 	n = strlen(r);
 	if (n > fieldssize) {
 		xfree(fields);
-		if ((fields = (char *) malloc(n+1)) == nil)
+		if ((fields = (char *) malloc(n+2)) == nil)  /* possibly 2 final \0s */
 			FATAL("out of space for fields in fldbld %d", n);
 		fieldssize = n;
 	}