[Issue 23654] execv_: toAStringz: memory corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 30 15:00:47 UTC 2023


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

--- Comment #11 from Steven Schveighoffer <schveiguy at gmail.com> ---
If you look at that commit from 2015, it was using alloca before, and now uses
malloc. But the issue is that the `toAStringz` which allocates an array of C
strings using the GC. This was the case before the 2015 change, and is still
the case now. So the GC was always used.

The issue that happened when moving to malloc is that the GC could clean up
those string items before they were sent to execv. When it was using alloca,
that went on the stack, and stacks are scanned.

The simple solution is to put that array on the GC.

Given that for at least 8 years, and probably more, using the GC was fine when
forking/execing a process, most likely it's either just fine, or it hangs so
infrequently that nobody has complained about it.

Using the GC for the string array along with all the strings is at least the
same risk as just allocating the strings using the GC.

--


More information about the Digitalmars-d-bugs mailing list