You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found a bug with JRuby's ENV constant's #[]= and #delete methods.
Environment variables cleared via ENV["FOO"] = nil or ENV.delete("FOO"),
are still set to their pre-cleared value under certain conditions.
In particular, you can still see the pre-cleared value in a PTY terminal
spawned after the environment variable was cleared. This is in contrast
to subshells started via backtick, system, or exec, where the cleared
value does not seem to be visible.
Using the example.rb code defined at the end:
$ jruby example.rb
originally : {:pty=>nil, :backtick=>nil, :env=>nil}
clearing via ENV["FOO"] = nil
after set : {:pty=>"something", :backtick=>"something", :env=>"something"}
after clear : {:pty=>"something", :backtick=>nil, :env=>nil}
clearing via ENV["FOO"] = ""
after set : {:pty=>"something else", :backtick=>"something else", :env=>"something else"}
after clear : {:pty=>"", :backtick=>"", :env=>""}
clearing via ENV.delete("FOO")
after set : {:pty=>"yet something else", :backtick=>"yet something else", :env=>"yet something else"}
after clear : {:pty=>"yet something else", :backtick=>nil, :env=>nil}
Note how the environment made available to the pty still has the old value of $FOO.
In contrast, MRI ruby does not leak the old environment variable to the PTY terminal:
$ mriruby example.rb
originally : {:pty=>nil, :backtick=>nil, :env=>nil}
clearing via ENV["FOO"] = nil
after set : {:pty=>"something", :backtick=>"something", :env=>"something"}
after clear : {:pty=>nil, :backtick=>nil, :env=>nil}
clearing via ENV["FOO"] = ""
after set : {:pty=>"something else", :backtick=>"something else", :env=>"something else"}
after clear : {:pty=>"", :backtick=>"", :env=>""}
clearing via ENV.delete("FOO")
after set : {:pty=>"yet something else", :backtick=>"yet something else", :env=>"yet something else"}
after clear : {:pty=>nil, :backtick=>nil, :env=>nil}
Example code follows:
# example.rbrequire'tempfile'require'pty'COMMAND=%!ruby -e "p ENV['FOO']"!deftesttf=Tempfile.new'output'output=beginstdout,stdin,pid=PTY.spawn"#{COMMAND} | tee #{tf.path}"stdout.readrescueErrno::EIO,IOErrortf.readensuretf.closeProcess.waitpidend{:pty=>eval(output),:backtick=>eval(`#{COMMAND}`),:env=>ENV["FOO"]}endoriginal=ENV["FOO"]puts"originally : #{test.inspect}"puts'clearing via ENV["FOO"] = nil'ENV["FOO"]="something"puts"\tafter set : #{test.inspect}"ENV["FOO"]=nilputs"\tafter clear : #{test.inspect}"puts'clearing via ENV["FOO"] = ""'ENV["FOO"]="something else"puts"\tafter set : #{test.inspect}"ENV["FOO"]=""puts"\tafter clear : #{test.inspect}"puts'clearing via ENV.delete("FOO")'ENV["FOO"]="yet something else"puts"\tafter set : #{test.inspect}"ENV.delete"FOO"puts"\tafter clear : #{test.inspect}"
The text was updated successfully, but these errors were encountered:
I've found a bug with JRuby's
ENV
constant's#[]=
and#delete
methods.Environment variables cleared via
ENV["FOO"] = nil
orENV.delete("FOO")
,are still set to their pre-cleared value under certain conditions.
In particular, you can still see the pre-cleared value in a
PTY
terminalspawned after the environment variable was cleared. This is in contrast
to subshells started via backtick,
system
, orexec
, where the clearedvalue does not seem to be visible.
Using the
example.rb
code defined at the end:Note how the environment made available to the pty still has the old value of
$FOO
.In contrast, MRI ruby does not leak the old environment variable to the
PTY
terminal:Example code follows:
The text was updated successfully, but these errors were encountered: