9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Charles Forsyth <charles.forsyth@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Why getenv replaces \0 with spaces in the returned value?
Date: Sat, 21 Jan 2017 08:22:13 +0000	[thread overview]
Message-ID: <CAOw7k5jWWc+Us6rWq_zwombmr41j7uve=z7EiARYHrnt5YwN-Q@mail.gmail.com> (raw)
In-Reply-To: <CAHL7psE-iCNyERXd0fP6EHiFunRgvQ9GiHtHkU_26kwE=ZW7EQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1505 bytes --]

Yes but other programs might like to read values left behind by rc, using
getenv

On Wed, 18 Jan 2017, 23:51 Giacomo Tesio, <giacomo@tesio.it> wrote:

> Yes that would be a plausible explanation but actually rc does not use
> getenv: it reads /env/ files directly.
>
> I've tried to remove the loop and I can't see any issue.
>
>
> Giacomo
>
>
> 2017-01-18 21:13 GMT+01:00 Charles Forsyth <charles.forsyth@gmail.com>:
> > Yes, it's the lists. Nothing will cope with \0 in a C string, so it's a
> good
> > choice as list of string element separator.
> >
> > On 18 January 2017 at 19:21, Fran. J Ballesteros <nemo@lsub.org> wrote:
> >>
> >> rc lists?
> >>
> >> > El 18 ene 2017, a las 17:45, Giacomo Tesio <giacomo@tesio.it>
> escribió:
> >> >
> >> > Hi, last night I noticed this strange post processing in 4th edition's
> >> > getenv:
> >> >
> https://github.com/brho/plan9/blob/master/sys/src/libc/9sys/getenv.c#L34-L41
> >> >
> >> >        seek(f, 0, 0);
> >> >        r = read(f, ans, s);
> >> >        if(r >= 0) {
> >> >            ep = ans + s - 1;
> >> >            for(p = ans; p < ep; p++)
> >> >                if(*p == '\0')
> >> >                    *p = ' ';
> >> >            ans[s] = '\0';
> >> >        }
> >> >
> >> > Anybody know why this replacement is done?
> >> > It does not seem a good fix to read/write or read/truncate races, but
> >> > I can't find a better explanation.
> >> >
> >> >
> >> > Giacomo
> >> >
> >>
> >>
> >
>
>

[-- Attachment #2: Type: text/html, Size: 3335 bytes --]

      reply	other threads:[~2017-01-21  8:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 16:45 Giacomo Tesio
2017-01-18 18:07 ` Ryan Gonzalez
2017-01-18 19:21 ` Fran. J Ballesteros
2017-01-18 20:13   ` Charles Forsyth
2017-01-18 23:48     ` Giacomo Tesio
2017-01-21  8:22       ` Charles Forsyth [this message]

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='CAOw7k5jWWc+Us6rWq_zwombmr41j7uve=z7EiARYHrnt5YwN-Q@mail.gmail.com' \
    --to=charles.forsyth@gmail.com \
    --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).