From: Ryan Gonzalez <rymg19@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Cc: 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: Wed, 18 Jan 2017 18:07:45 +0000 [thread overview]
Message-ID: <78ffadjikog5caambyi381mus-0@mailer.nylas.com> (raw)
In-Reply-To: <CAHL7psF2F7P+vbBRRX02qA++2R7E3jk29B7V-zUw5YNCVDW2nQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]
Just a wild guess, but I think it could be because getenv just returns a null-
terminated string with no indication of its length. If C code were to do
pretty much anything on the environment variable in question, it would always
be truncated. e.g. with VAR=ABC\0DEF, the C string processing functions would
assume it ended after ABC.
As a side note, Linux does nothing and simply returns it as-is. I wonder why
the Posix guys haven't added a getenv_n(var, &length) function yet...
\--
Ryan (ライアン)
Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else
<http://refi64.com/>
On Jan 18 2017, at 10:47 am, Giacomo Tesio <giacomo@tesio.it> wrote:
> 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: 2328 bytes --]
next prev parent reply other threads:[~2017-01-18 18:07 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 [this message]
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
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=78ffadjikog5caambyi381mus-0@mailer.nylas.com \
--to=rymg19@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).