From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 References: In-Reply-To: From: Charles Forsyth Date: Sat, 21 Jan 2017 08:22:13 +0000 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=94eb2c05f15452e61205469677b6 Subject: Re: [9fans] Why getenv replaces \0 with spaces in the returned value? Topicbox-Message-UUID: b23e4f60-ead9-11e9-9d60-3106f5b1d025 --94eb2c05f15452e61205469677b6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Yes but other programs might like to read values left behind by rc, using getenv On Wed, 18 Jan 2017, 23:51 Giacomo Tesio, 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 : > > 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 wrote: > >> > >> rc lists? > >> > >> > El 18 ene 2017, a las 17:45, Giacomo Tesio > escribi=C3=B3: > >> > > >> > 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 =3D read(f, ans, s); > >> > if(r >=3D 0) { > >> > ep =3D ans + s - 1; > >> > for(p =3D ans; p < ep; p++) > >> > if(*p =3D=3D '\0') > >> > *p =3D ' '; > >> > ans[s] =3D '\0'; > >> > } > >> > > >> > Anybody know why this replacement is done? > >> > It does not seem a good fix to read/write or read/truncate races, bu= t > >> > I can't find a better explanation. > >> > > >> > > >> > Giacomo > >> > > >> > >> > > > > --94eb2c05f15452e61205469677b6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Yes but other programs might like to read values left behind by rc, using g= etenv

On Wed, 18 Jan 201= 7, 23:51 Giacomo Tesio, <giacomo@tes= io.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@gmai= l.com>:
> Yes, it's the lists. Nothing will cope with \0 in a C string, so i= t'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.i= t> escribi=C3=B3:
>> >
>> > 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/get= env.c#L34-L41
>> >
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 seek(f, 0, 0);
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 r =3D read(f, ans, s);
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 if(r >=3D 0) {
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep =3D ans + s - 1;<= br class=3D"gmail_msg"> >> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for(p =3D ans; p <= ; ep; p++)
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if(*p = =3D=3D '\0')
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 *p =3D ' ';
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ans[s] =3D '\0&#= 39;;
>> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>> >
>> > Anybody know why this replacement is done?
>> > It does not seem a good fix to read/write or read/truncate ra= ces, but
>> > I can't find a better explanation.
>> >
>> >
>> > Giacomo
>> >
>>
>>
>

--94eb2c05f15452e61205469677b6--