Repository navigation
Copy ENV before building a spawned process's environment - #10108
Open
sampokuokkanen wants to merge 1 commit into
Open
sampokuokkanen wants to merge 1 commit into
sampokuokkanen wants to merge 1 commit into
Conversation
Without an env hash, execargParentStart1 walked the live ENV hash, and buildEnvp had sized its array from ENV.size first. If another thread added a key during the walk, it raised ArrayIndexOutOfBoundsException (jruby#10031): Thread.new { i = 0; loop { ENV["REPRO_#{i += 1}"] = "x" } } 100.times { `echo` } Copy ENV first, as the path with an env hash already does and as MRI does with rb_env_to_hash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #10031.
Without an env hash,
spawn,system, backticks andpopenwalked the liveENVinto an array sized fromENV.size. If another thread added a key meanwhile, it raisedArrayIndexOutOfBoundsException:Now ENV is copied first, as the env-hash path already does and as CRuby does in
rb_execarg_parent_start1withrb_env_to_hash.Tested with a stress variant (running
/usr/bin/trueby full path to avoid the PATH race below): 9000 backticks with no errors, against about 250 exceptions per 3000 before. Process, popen and ENV specs pass.Noticed but not fixed:
ENV["PATH"]can return nil under concurrent writes (about once in 2 million reads) and a spawn can fail withErrno::ENOENT. CRuby locks every ENV operation (ENV_LOCKING).JRubyPOSIXHandler.getEnvwalks the live ENV the same way.