9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Cc: 9front@9front.org
Subject: Re: [9front] upas/Mail: fix multiple suicides (use after free, double free) in mbox.c (patch)
Date: Sun, 11 Apr 2021 19:59:35 -0700	[thread overview]
Message-ID: <97FDE9A5306132622D1D4F91D0453FA9@eigenstate.org> (raw)
In-Reply-To: <9F7C695CA1C76DA9023BE33F535E8C8F@9lab.org>

Quoth igor@9lab.org:
> Below is a patch (inline) that fixes two variants of a suicide (use
> after free, double free) in Mail/mbox.c on latest 9front 'Mit
> Fruchtgeschmack' (explanation with reproducible test instructions
> below) when messages are deleted/moved in bulk:
> 
> <patch>
> diff -r 4dfbef4fa4ac sys/src/cmd/upas/Mail/mbox.c
> --- a/sys/src/cmd/upas/Mail/mbox.c	Sat Apr 03 19:32:47 2021 +0200
> +++ b/sys/src/cmd/upas/Mail/mbox.c	Fri Apr 09 02:54:10 2021 +0200
> @@ -675,10 +675,11 @@
>  static void
>  mbflush(char **, int)
>  {
> -	int i, j, ln, fd;
> +	int i, j, ln, fd, nmesg;
>  	char *path;
>  	Mesg *m, *p;
>  
> +	nmesg = mbox.nmesg;
>  	path = estrjoin(maildir, "/ctl", nil);
>  	fd = open(path, OWRITE);
>  	free(path);
> @@ -708,11 +709,13 @@
>  			mbredraw(m->child[j], 1, 1);
>   	}
>  
> -	for(i = 0, j = 0; i < mbox.nmesg; i++){
> +	for(i = 0, j = 0; i < nmesg; i++){
>  		m = mbox.mesg[i];
> -		if((m->state & Szap) != 0)
> +		if((m->state & Szap) != 0){
>  			mesgfree(m);
> -		else
> +			mbox.mesg[i] = nil;
> +			mbox.nmesg--;
> +		}else
>  			mbox.mesg[j++] = m;
>  	}

I think I prefer this patch:

diff -r 503c5ef2d2b5 sys/src/cmd/upas/Mail/mbox.c
--- a/sys/src/cmd/upas/Mail/mbox.c	Sun Apr 11 20:20:41 2021 +0200
+++ b/sys/src/cmd/upas/Mail/mbox.c	Sun Apr 11 19:58:55 2021 -0700
@@ -715,6 +715,7 @@
 		else
 			mbox.mesg[j++] = m;
 	}
+	mbox.nmesg = j;
 		
 	close(fd);
 	fprint(mbox.ctl, "clean\n");


  reply	other threads:[~2021-04-12  7:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11 20:19 igor
2021-04-12  2:59 ` ori [this message]
2021-04-12 12:49   ` igor
2021-04-12 15:51     ` 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=97FDE9A5306132622D1D4F91D0453FA9@eigenstate.org \
    --to=ori@eigenstate.org \
    --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).