9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Kristo <kristo.ilmari@gmail.com>
To: 9front@9front.org
Subject: [9front] [PATCH] awk: don't write an extra NUL past the end of a block
Date: Tue, 23 Jan 2024 09:44:12 +0200	[thread overview]
Message-ID: <da549402-071f-4185-97d2-5c4cd8e18ecb@gmail.com> (raw)

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);


             reply	other threads:[~2024-01-23  7:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23  7:44 Kristo [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da549402-071f-4185-97d2-5c4cd8e18ecb@gmail.com \
    --to=kristo.ilmari@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).