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.
This commit is contained in:
Jacob Moody 2024-01-23 21:10:41 +00:00
parent 26c21f9b5d
commit 207cd2812f

View file

@ -261,7 +261,7 @@ void fldbld(void) /* create fields from current record */
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;
}