[Issue 24549] std.process.environment.get(null) segfaults

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 13 22:19:07 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24549

Steven Schveighoffer <schveiguy at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at gmail.com

--- Comment #1 from Steven Schveighoffer <schveiguy at gmail.com> ---
The underlying issue is that `std.internal.cstring.tempCString` returns a
`null` pointer if the input string is an empty string with a null pointer.

This is surprising, and seems to have been done as a hack to work around issue
14980

I would not expect to get a null pointer when passing in an empty string, I'd
expect an empty string. This has a seemingly "unforseen" effect on code that is
accepting of a string, and blindly passes to `tempCString` for calling a C lib
-- if the library function doesn't handle null pointers, or handles them
differently than non-null empty strings, then it may crash or do something
unexpected.

The Linux `getenv` function is crashing on the null pointer (BTW, this does not
happen on MacOS).

--


More information about the Digitalmars-d-bugs mailing list