9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] awk: don't write an extra NUL past the end of a block
@ 2024-01-23  7:44 Kristo
  2024-01-23 16:53 ` Jacob Moody
  0 siblings, 1 reply; 8+ messages in thread
From: Kristo @ 2024-01-23  7:44 UTC (permalink / raw)
  To: 9front

When splitting a record into individual fields awk seems to write an
extra NUL at the end, which is not an issue when a record fits in the
default buffer. However, with larger records the buffer is allocated to
length of the string + 1, meaning that the extra NUL goes past the end
of the block and causes a "mem user overflow" panic.

diff 26c21f9b5d06296d13f40b53de14e22007e189c2 uncommitted
--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -287,7 +287,6 @@
 			while (*r != ' ' && *r != '\t' && *r != '\n' && *r != '\0');
 			*fr++ = 0;
 		}
-		*fr = 0;
 	} else if ((sep = *inputFS) == 0) {		/* new: FS="" => 1 char/field */
 		for (i = 0; *r != 0; r += w) {
 			char buf[UTFmax + 1];
@@ -320,7 +319,6 @@
 			if (*r++ == 0)
 				break;
 		}
-		*fr = 0;
 	}
 	if (i > nfields)
 		FATAL("record `%.30s...' has too many fields; can't happen", r);


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-23 21:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23  7:44 [9front] [PATCH] awk: don't write an extra NUL past the end of a block Kristo
2024-01-23 16:53 ` Jacob Moody
2024-01-23 17:40   ` qwx
2024-01-23 17:45     ` qwx
2024-01-23 17:50       ` Jacob Moody
2024-01-23 18:47         ` Aw: " Alexander Shendi
2024-01-23 18:32   ` Kristo
2024-01-23 21:27     ` Jacob Moody

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).