Open
Conversation
| assert_no_match(/Amiga/, line) | ||
| assert_no_match(/paper/, line) | ||
| if main_ractor? | ||
| tmp = open(tmpfilename, "r") |
Check failure
Code scanning / CodeQL
Use of `Kernel.open` or `IO.read` or similar sinks with a non-constant value Critical test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 months ago
The best way to fix this problem is to replace all instances of open(tmpfilename, ...) with File.open(tmpfilename, ...). This ensures that the file is opened directly, and Ruby will not interpret the filename as a shell command, even if it starts with a |. The change should be made in all places within the shown code where open is called with a variable filename. No additional imports or method definitions are needed, as File is part of Ruby's core library.
Suggested changeset
1
test/ruby/test_whileuntil.rb
| @@ -7,7 +7,7 @@ | ||
| Dir.mktmpdir("ruby_while_tmp") {|tmpdir| | ||
| tmpfilename = "#{tmpdir}/ruby_while_tmp.#{$$}" | ||
|
|
||
| tmp = open(tmpfilename, "w") | ||
| tmp = File.open(tmpfilename, "w") | ||
| tmp.print "tvi925\n"; | ||
| tmp.print "tvi920\n"; | ||
| tmp.print "vt100\n"; | ||
| @@ -15,7 +15,7 @@ | ||
| tmp.print "paper\n"; | ||
| tmp.close | ||
|
|
||
| tmp = open(tmpfilename, "r") | ||
| tmp = File.open(tmpfilename, "r") | ||
| assert_instance_of(File, tmp) | ||
|
|
||
| while line = tmp.gets() | ||
| @@ -26,7 +26,7 @@ | ||
| assert_match(/vt100/, line) | ||
| tmp.close | ||
|
|
||
| tmp = open(tmpfilename, "r") | ||
| tmp = File.open(tmpfilename, "r") | ||
| while line = tmp.gets() | ||
| next if /vt100/ =~ line | ||
| assert_no_match(/vt100/, line) | ||
| @@ -35,7 +35,7 @@ | ||
| assert_no_match(/vt100/, line) | ||
| tmp.close | ||
|
|
||
| tmp = open(tmpfilename, "r") | ||
| tmp = File.open(tmpfilename, "r") | ||
| while line = tmp.gets() | ||
| lastline = line | ||
| line = line.gsub(/vt100/, 'VT100') | ||
| @@ -60,7 +60,7 @@ | ||
| assert_equal(220, sum) | ||
|
|
||
| if main_ractor? | ||
| tmp = open(tmpfilename, "r") | ||
| tmp = File.open(tmpfilename, "r") | ||
| while line = tmp.gets() | ||
| break if $. == 3 | ||
| assert_no_match(/vt100/, line) |
Copilot is powered by AI and may make mistakes. Always verify output.
4a3a2d7 to
f3aa1ea
Compare
88d6f7b to
8048328
Compare
55d9388 to
ca12e17
Compare
This tests for ractor safety issues as well as concurrency issues. You can enable these tests with RUBY_TESTS_WITH_RACTORS=X when running `make test-all TESTS=test/ruby`. Running tests with ractors is currently only working for tests under the "test/ruby" directory. You should also use the `.excludes-ractor` excludes directory. For example: ``` EXCLUDES=test/.excludes-ractor RUBY_TESTS_WITH_RACTORS=3 TESTS=test/ruby make test-all ``` This will create 3 ractors for each test method, run the test method inside each ractor and then call `join` on the ractors. Then, it's ready to process the next test. The reason we do this instead of taking all the tests and dividing them between the number of ractors is: * We want to run each test under concurrency load to test whether or not it is safe under ractors. If it isn't safe, we know it's something to do with this specific test. * If we get a segfault or error, we know the error is coming from this test alone, not interactions with other tests. The disadvantage of this approach is: * It's slower than dividing the tests between the number of ractors running. * This might not uncover ractor scheduling issues that would show up when you have long-running ractors.
ca12e17 to
c25554d
Compare
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.
No description provided.