9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: arisawa <arisawa@ar.aichi-u.ac.jp>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] bug in authdial()
Date: Sat, 21 May 2016 16:00:32 +0900	[thread overview]
Message-ID: <F8B3028D-9E02-425A-A92F-FB88A5247587@ar.aichi-u.ac.jp> (raw)
In-Reply-To: <e2cc68c67e302f97bc67473b30c2a427@9netics.com>

Hello,

> 2016/05/21 11:25、Skip Tavakkolian <9nut@9netics.com> のメール:
> 
> i think this fix is correct; i'm not sure why tokenize didn't have a
> problem walking a buffer it expects to be null terminated.

I agree with skip.

the man wait(2) says:
	The underlying system call is await, which fills in the n-
	byte buffer s with a textual representation of the pid,
	times, and exit string.  There is no terminal NUL.  The
	return value is the length, in bytes, of the data.

thus the typical usage of await is:
Waitmsg*
wait(void)
{
	int n, l;
	char buf[512], *fld[5];
	Waitmsg *w;

	n = await(buf, sizeof buf-1);
	if(n < 0)
		return nil;
	buf[n] = '\0';
	if(tokenize(buf, fld, nelem(fld)) != nelem(fld)){
		werrstr("couldn't parse wait message");
		return nil;
	}


/sys/src/libc/9sys/dial.c may be fixed as follows:

static int
reap(Dest *dp)
{
	char exitsts[2*ERRMAX];
+	int n;
-	if (outstandingprocs(dp) && await(exitsts, sizeof exitsts) >= 0) {
+	if (outstandingprocs(dp) && (n = await(exitsts, sizeof exitsts-1)) >= 0) {
+		exitsts[n] = 0;
		notedeath(dp, exitsts);
		return 0;
	}
	return -1;
}

probably 2*ERRMAX is enough for await().

I wonder why await() returns non-terminated string?





  reply	other threads:[~2016-05-21  7:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18  0:43 arisawa
2016-05-18  9:14 ` cinap_lenrek
2016-05-19 14:45   ` arisawa
2016-05-19 15:43     ` lucio
2016-05-19 15:48       ` Charles Forsyth
2016-05-20  4:58         ` arisawa
2016-05-20 22:04         ` Skip Tavakkolian
2016-05-20 22:25           ` Charles Forsyth
2016-05-21  4:46             ` arisawa
2016-05-21 17:04               ` erik quanstrom
2016-05-21 23:11                 ` Lyndon Nerenberg
2016-05-21 23:16                   ` erik quanstrom
2016-05-21 17:06             ` erik quanstrom
2016-05-21  3:24           ` arisawa
2016-05-23 14:27           ` arisawa
2016-05-20 22:07         ` Skip Tavakkolian
2016-05-21  2:25           ` Skip Tavakkolian
2016-05-21  7:00             ` arisawa [this message]
2016-05-21 16:51               ` erik quanstrom
2016-05-21 21:45                 ` Skip Tavakkolian
2016-05-21 21:48                   ` erik quanstrom
2016-05-21 22:16                     ` Skip Tavakkolian
2016-05-21 21:50                   ` erik quanstrom
2016-05-21 22:17                     ` Skip Tavakkolian
2016-05-21 22:34                       ` erik quanstrom
2016-05-21 23:03                         ` Skip Tavakkolian
2016-05-21 23:31                           ` erik quanstrom
2016-05-21 22:53                     ` David du Colombier
2016-05-18 13:06 ` Charles Forsyth
2016-05-18 17:03   ` Skip Tavakkolian
2016-05-19  4:07     ` arisawa

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=F8B3028D-9E02-425A-A92F-FB88A5247587@ar.aichi-u.ac.jp \
    --to=arisawa@ar.aichi-u.ac.jp \
    --cc=9fans@9fans.net \
    /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).