Skip to content

Commit 0454642

Browse files
committed
Ruby: Model deep_dup and presence
1 parent 9f26085 commit 0454642

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActiveSupport.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ module ActiveSupport {
6767
}
6868
}
6969

70+
/**
71+
* Extensions to the `Object` class.
72+
*/
73+
module Object {
74+
/** Flow summary for methods which can return the receiver. */
75+
private class IdentitySummary extends SimpleSummarizedCallable {
76+
IdentitySummary() { this = ["presence", "deep_dup"] }
77+
78+
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
79+
input = "Argument[self]" and
80+
output = "ReturnValue" and
81+
preservesValue = true
82+
}
83+
}
84+
}
85+
7086
/**
7187
* Extensions to the `Enumerable` module.
7288
*/

ruby/ql/test/library-tests/frameworks/active_support/ActiveSupportDataFlow.expected

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
failures
2+
| active_support.rb:276:10:276:26 | # $hasTaintFlow=a | Missing result:hasTaintFlow=a |
3+
| active_support.rb:278:10:278:26 | # $hasTaintFlow=a | Missing result:hasTaintFlow=a |
24
edges
35
| active_support.rb:10:9:10:18 | call to source : | active_support.rb:11:10:11:10 | x : |
46
| active_support.rb:11:10:11:10 | x : | active_support.rb:11:10:11:19 | call to at |
@@ -166,14 +168,18 @@ edges
166168
| active_support.rb:267:34:267:34 | a : | active_support.rb:267:7:267:35 | call to new : |
167169
| active_support.rb:268:7:268:7 | x : | active_support.rb:268:7:268:16 | call to to_param : |
168170
| active_support.rb:268:7:268:16 | call to to_param : | active_support.rb:269:8:269:8 | y |
169-
| active_support.rb:273:7:273:16 | call to source : | active_support.rb:274:20:274:20 | a : |
170-
| active_support.rb:274:7:274:21 | call to new : | active_support.rb:275:7:275:7 | x : |
171-
| active_support.rb:274:20:274:20 | a : | active_support.rb:274:7:274:21 | call to new : |
172-
| active_support.rb:275:7:275:7 | x : | active_support.rb:275:7:275:17 | call to existence : |
173-
| active_support.rb:275:7:275:17 | call to existence : | active_support.rb:276:8:276:8 | y |
174-
| active_support.rb:275:7:275:17 | call to existence : | active_support.rb:277:7:277:7 | y : |
175-
| active_support.rb:277:7:277:7 | y : | active_support.rb:277:7:277:17 | call to existence : |
176-
| active_support.rb:277:7:277:17 | call to existence : | active_support.rb:278:8:278:8 | z |
171+
| active_support.rb:281:7:281:16 | call to source : | active_support.rb:282:8:282:8 | x : |
172+
| active_support.rb:281:7:281:16 | call to source : | active_support.rb:282:8:282:8 | x : |
173+
| active_support.rb:282:8:282:8 | x : | active_support.rb:282:8:282:17 | call to presence |
174+
| active_support.rb:282:8:282:8 | x : | active_support.rb:282:8:282:17 | call to presence |
175+
| active_support.rb:284:7:284:16 | call to source : | active_support.rb:285:8:285:8 | y : |
176+
| active_support.rb:284:7:284:16 | call to source : | active_support.rb:285:8:285:8 | y : |
177+
| active_support.rb:285:8:285:8 | y : | active_support.rb:285:8:285:17 | call to presence |
178+
| active_support.rb:285:8:285:8 | y : | active_support.rb:285:8:285:17 | call to presence |
179+
| active_support.rb:289:7:289:16 | call to source : | active_support.rb:290:8:290:8 | x : |
180+
| active_support.rb:289:7:289:16 | call to source : | active_support.rb:290:8:290:8 | x : |
181+
| active_support.rb:290:8:290:8 | x : | active_support.rb:290:8:290:17 | call to deep_dup |
182+
| active_support.rb:290:8:290:8 | x : | active_support.rb:290:8:290:17 | call to deep_dup |
177183
nodes
178184
| active_support.rb:10:9:10:18 | call to source : | semmle.label | call to source : |
179185
| active_support.rb:11:10:11:10 | x : | semmle.label | x : |
@@ -393,15 +399,24 @@ nodes
393399
| active_support.rb:268:7:268:7 | x : | semmle.label | x : |
394400
| active_support.rb:268:7:268:16 | call to to_param : | semmle.label | call to to_param : |
395401
| active_support.rb:269:8:269:8 | y | semmle.label | y |
396-
| active_support.rb:273:7:273:16 | call to source : | semmle.label | call to source : |
397-
| active_support.rb:274:7:274:21 | call to new : | semmle.label | call to new : |
398-
| active_support.rb:274:20:274:20 | a : | semmle.label | a : |
399-
| active_support.rb:275:7:275:7 | x : | semmle.label | x : |
400-
| active_support.rb:275:7:275:17 | call to existence : | semmle.label | call to existence : |
401-
| active_support.rb:276:8:276:8 | y | semmle.label | y |
402-
| active_support.rb:277:7:277:7 | y : | semmle.label | y : |
403-
| active_support.rb:277:7:277:17 | call to existence : | semmle.label | call to existence : |
404-
| active_support.rb:278:8:278:8 | z | semmle.label | z |
402+
| active_support.rb:281:7:281:16 | call to source : | semmle.label | call to source : |
403+
| active_support.rb:281:7:281:16 | call to source : | semmle.label | call to source : |
404+
| active_support.rb:282:8:282:8 | x : | semmle.label | x : |
405+
| active_support.rb:282:8:282:8 | x : | semmle.label | x : |
406+
| active_support.rb:282:8:282:17 | call to presence | semmle.label | call to presence |
407+
| active_support.rb:282:8:282:17 | call to presence | semmle.label | call to presence |
408+
| active_support.rb:284:7:284:16 | call to source : | semmle.label | call to source : |
409+
| active_support.rb:284:7:284:16 | call to source : | semmle.label | call to source : |
410+
| active_support.rb:285:8:285:8 | y : | semmle.label | y : |
411+
| active_support.rb:285:8:285:8 | y : | semmle.label | y : |
412+
| active_support.rb:285:8:285:17 | call to presence | semmle.label | call to presence |
413+
| active_support.rb:285:8:285:17 | call to presence | semmle.label | call to presence |
414+
| active_support.rb:289:7:289:16 | call to source : | semmle.label | call to source : |
415+
| active_support.rb:289:7:289:16 | call to source : | semmle.label | call to source : |
416+
| active_support.rb:290:8:290:8 | x : | semmle.label | x : |
417+
| active_support.rb:290:8:290:8 | x : | semmle.label | x : |
418+
| active_support.rb:290:8:290:17 | call to deep_dup | semmle.label | call to deep_dup |
419+
| active_support.rb:290:8:290:17 | call to deep_dup | semmle.label | call to deep_dup |
405420
subpaths
406421
#select
407422
| active_support.rb:182:10:182:13 | ...[...] | active_support.rb:180:10:180:17 | call to source : | active_support.rb:182:10:182:13 | ...[...] | $@ | active_support.rb:180:10:180:17 | call to source : | call to source : |
@@ -418,3 +433,6 @@ subpaths
418433
| active_support.rb:210:10:210:13 | ...[...] | active_support.rb:205:32:205:40 | call to source : | active_support.rb:210:10:210:13 | ...[...] | $@ | active_support.rb:205:32:205:40 | call to source : | call to source : |
419434
| active_support.rb:211:10:211:13 | ...[...] | active_support.rb:205:21:205:29 | call to source : | active_support.rb:211:10:211:13 | ...[...] | $@ | active_support.rb:205:21:205:29 | call to source : | call to source : |
420435
| active_support.rb:211:10:211:13 | ...[...] | active_support.rb:205:32:205:40 | call to source : | active_support.rb:211:10:211:13 | ...[...] | $@ | active_support.rb:205:32:205:40 | call to source : | call to source : |
436+
| active_support.rb:282:8:282:17 | call to presence | active_support.rb:281:7:281:16 | call to source : | active_support.rb:282:8:282:17 | call to presence | $@ | active_support.rb:281:7:281:16 | call to source : | call to source : |
437+
| active_support.rb:285:8:285:17 | call to presence | active_support.rb:284:7:284:16 | call to source : | active_support.rb:285:8:285:17 | call to presence | $@ | active_support.rb:284:7:284:16 | call to source : | call to source : |
438+
| active_support.rb:290:8:290:17 | call to deep_dup | active_support.rb:289:7:289:16 | call to source : | active_support.rb:290:8:290:17 | call to deep_dup | $@ | active_support.rb:289:7:289:16 | call to source : | call to source : |

ruby/ql/test/library-tests/frameworks/active_support/active_support.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,16 @@ def m_pathname_existence
276276
sink y # $hasTaintFlow=a
277277
z = y.existence
278278
sink z # $hasTaintFlow=a
279+
280+
def m_presence
281+
x = source "a"
282+
sink x.presence # $hasValueFlow=a
283+
284+
y = source 123
285+
sink y.presence # $hasValueFlow=123
286+
end
287+
288+
def m_deep_dup
289+
x = source "a"
290+
sink x.deep_dup # $hasValueFlow=a
279291
end

0 commit comments

Comments
 (0)