9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Why getenv replaces \0 with spaces in the returned value?
@ 2017-01-18 16:45 Giacomo Tesio
  2017-01-18 18:07 ` Ryan Gonzalez
  2017-01-18 19:21 ` Fran. J Ballesteros
  0 siblings, 2 replies; 6+ messages in thread
From: Giacomo Tesio @ 2017-01-18 16:45 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-01-21  8:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 16:45 [9fans] Why getenv replaces \0 with spaces in the returned value? 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 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).