Skip to content

Commit ef88f3e

Browse files
authored
Merge pull request #16377 from hmac/hmac-sanitization-fp
Ruby: Fix StringSubstitutionCall charpred
2 parents 9bfb189 + f7fc2e0 commit ef88f3e

File tree

2 files changed

+10
-3
lines changed
  • ruby/ql
    • lib/codeql/ruby/frameworks/core
    • test/query-tests/security/cwe-116/IncompleteSanitization

2 files changed

+10
-3
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/String.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ class StringSubstitutionCall extends DataFlow::CallNode {
1919
StringSubstitutionCall() {
2020
this.getMethodName() = ["sub", "sub!", "gsub", "gsub!"] and
2121
exists(this.getReceiver()) and
22-
this.getNumberOfArguments() = 2
23-
or
24-
this.getNumberOfArguments() = 1 and exists(this.getBlock())
22+
(
23+
this.getNumberOfArguments() = 2
24+
or
25+
this.getNumberOfArguments() = 1 and exists(this.getBlock())
26+
)
2527
}
2628

2729
/**

ruby/ql/test/query-tests/security/cwe-116/IncompleteSanitization/tst.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,8 @@ def bad_path_sanitizer(p1, p2)
268268
p1.sub! "/../", "" # NOT OK
269269
p2.sub "/../", "" # NOT OK
270270
end
271+
272+
def each_line_sanitizer(p1)
273+
p1.each_line("\n") do |l| # OK - does no sanitization
274+
end
275+
end

0 commit comments

Comments
 (0)