Thread overview
[Issue 15783] Junk is written into environment variable after assigning null to it
Mar 18, 2016
e10s
Mar 18, 2016
Simen Kjaeraas
Apr 03, 2017
Roman
Jun 25, 2017
Roman
Jun 25, 2017
Roman
March 18, 2016
https://issues.dlang.org/show_bug.cgi?id=15783

e10s <electrolysis.jp+d@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |electrolysis.jp+d@gmail.com

--- Comment #1 from e10s <electrolysis.jp+d@gmail.com> ---
Test case:

import std.conv;
import std.stdio;
import std.string;
import core.sys.posix.stdlib;

void main()
{
    immutable key = "AAAAAAAA".toStringz;
    foreach (i; 0 .. 100)
    {
        setenv(key, null, 1);
        const r = getenv(key);
        if (r && *r)
        {
            writefln("%s %s %s", i, r, r.to!string);
        }
    }
}

Result:
http://melpon.org/wandbox/permlink/cqfITPRJMSKOD60q

It's terrible. What does getenv return?

--
March 18, 2016
https://issues.dlang.org/show_bug.cgi?id=15783

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras@gmail.com

--- Comment #2 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
core.sys.posix.stdlib.setenv is a simple wrapper around the posix function of the same name, and should have the same behavior. This is not a bug in core.sys.posix.stdlib, but one might argue there is one in phobos' std.process.environment.

The OS is simply following the standard, which says nothing about how to handle
nulls:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html

--
April 03, 2017
https://issues.dlang.org/show_bug.cgi?id=15783

--- Comment #3 from Roman <freeslave93@gmail.com> ---
Still issue for 2.073.2

Can we just decide that providing the null means removing environment variable or setting it to empty string? Better make it behave the same way as on Windows (not sure what's behavior though).

--
June 25, 2017
https://issues.dlang.org/show_bug.cgi?id=15783

--- Comment #4 from Roman <freeslave93@gmail.com> ---
Was fixed in https://github.com/dlang/phobos/pull/5324
Can we get this closed?

--
June 25, 2017
https://issues.dlang.org/show_bug.cgi?id=15783

Roman <freeslave93@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
June 25, 2017
https://issues.dlang.org/show_bug.cgi?id=15783

greensunny12@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--- Comment #5 from greensunny12@gmail.com ---
@Roman: If you reference the Bugzilla issue(s) in your PRs, they will be
automatically closed:

https://github.com/dlang-bots/dlang-bot#automated-references

There are other advantages of doing this as well, e.g. referenced issues will be listed on the changelog.

--