Skip to content

Commit

Permalink
Safe value for unknown index into all literals array
Browse files Browse the repository at this point in the history
  • Loading branch information
presidentbeef committed May 8, 2021
1 parent bedbfd3 commit 6c1d8bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/brakeman/processors/lib/call_conversion_helper.rb
Expand Up @@ -76,6 +76,8 @@ def process_array_access array, args, original_exp = nil

#Have to do this because first element is :array and we have to skip it
array[1..-1][index] or original_exp
elsif all_literals? array
safe_literal(array.line)
else
original_exp
end
Expand Down
15 changes: 15 additions & 0 deletions test/tests/alias_processor.rb
Expand Up @@ -130,6 +130,14 @@ def test_array_fetch
RUBY
end

def test_array_fetch_unknown_literal
assert_alias ':BRAKEMAN_SAFE_LITERAL', <<-RUBY
x = [1, 2, 3]
y = x.fetch(z)
y
RUBY
end

def test_array_append
assert_alias '[1, 2, 3]', <<-RUBY
x = [1]
Expand Down Expand Up @@ -221,6 +229,13 @@ def test_hash_fetch
RUBY
end

def test_hash_fetch_unknown_literal
assert_alias ':BRAKEMAN_SAFE_LITERAL', <<-RUBY
x = { a: 0, b: 1, c: 3 }
x.fetch(:z)
RUBY
end

def test_hash_update
assert_alias "2", <<-RUBY
@foo = {
Expand Down

0 comments on commit 6c1d8bc

Please sign in to comment.