9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] werc memory over flow
Date: Sat, 12 Mar 2022 12:54:38 +0100	[thread overview]
Message-ID: <CC7138DE00DDE7F6259D949AFAE27A21@felloff.net> (raw)
In-Reply-To: <CDCBC180CF87AAF0F4BC5AC7D4F7791B@felloff.net>

actually, i think i found it (by staring at the code).

the code at the done label was unconditionally inserting
NUL terminator, without the final adjbuf() ensuring
theres space for it.

the patch gets rid of the label, so we wont skip the
final adjbuf().

diff d52f25ecdcf1dc8ee8d278c8da44159d82d8dd8f uncommitted
--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -1934,7 +1934,7 @@
 					}
 				}
 				if (*c == 0)	/* at end */
-					goto done;
+					break;
 				adjbuf(&buf, &bufsz, 2+pb-buf, recsize, &pb, "gsub");
 				*pb++ = *c++;
 				if (pb > buf + bufsz)	/* BUG: not sure of this test */
@@ -1962,8 +1962,12 @@
 						*pb++ = *sptr++;
 				}
 				c = patbeg + patlen;
-				if ((c[-1] == 0) || (*c == 0))
-					goto done;
+				if (c[-1] == 0){
+					c--;
+					break;
+				}
+				if (*c == 0)
+					break;
 				if (pb > buf + bufsz)
 					FATAL("gsub result1 %.30s too big; can't happen", buf);
 				mflag = 1;
@@ -1973,7 +1977,7 @@
 		adjbuf(&buf, &bufsz, 1+strlen(sptr)+pb-buf, 0, &pb, "gsub");
 		while ((*pb++ = *sptr++) != 0)
 			;
-	done:	if (pb > buf + bufsz)
+		if (pb > buf + bufsz)
 			FATAL("gsub result2 %.30s too big; can't happen", buf);
 		*pb = '\0';
 		setsval(x, buf);	/* BUG: should be able to avoid copy + free */

--
cinap

  reply	other threads:[~2022-03-12 12:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11  6:24 william
2022-03-11  6:33 ` ori
2022-03-11 15:18 ` ori
2022-03-12 11:23   ` cinap_lenrek
2022-03-12 11:54     ` cinap_lenrek [this message]
2022-03-12 12:34       ` cinap_lenrek
2022-03-13  7:27         ` william
2022-03-13 21:16           ` cinap_lenrek
2022-03-12 13:27       ` Steve Simon
2022-03-12 14:38         ` Steffen Nurpmeso
2022-03-11 16:49 ` Nick Owens
2022-03-11 20:13 ` cinap_lenrek

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=CC7138DE00DDE7F6259D949AFAE27A21@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --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).