Use double-NULL byte for empty process environments on Windows #1686
+11
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. ↩