Use double-NULL byte for empty process environments on Windows#1686
Use double-NULL byte for empty process environments on Windows#1686bakpakin merged 3 commits intojanet-lang:masterfrom
Conversation
|
For future reference, binaries that are compiled with MinGW can fail on Windows (not WINE) when launched with This is obviously not a great solution but I think it's the most reasonable approach. All the alternatives I could think of (e.g. silently adding |
|
Looks good, that is a subtle issue. A missing PATH environment variable is a recipe for all sorts of issues, so I wouldn't worry too much about that failure mode |
While working on Churlish (a wrapper around the
curlCLI utility), I noticed intermittent errors while usingos/spawnon Windows. After further investigation, I believe the issue is that I was callingos/spawnwith an effectively empty1 environment and that this was causingCreateProcessto occasionally fail due to a bug inos_execute_env.The issue is that an empty environment block needs to be double-NULL terminated as described in more detail in Microsoft's documentation:
I suspect that the error was intermittent because sometimes the memory being accessed happened to have a second NULL byte after the first. This was not guaranteed to be the case.
This commit adds an extra NULL byte if the environment is empty. It also adds a test.
Footnotes
I was calling
os/spawnwith a struct that mapped:in,:outand:errto pipes. I mistakenly thought that this meant I needed to use:peas the second argument toos/spawn. Because the struct contained no other values, it was empty for the purposes ofos_execute_env. ↩