Skip to content

Commit f9b952f

Browse files
committed
Ruby: Pathname use TypeTracker instead of local flow
1 parent d5478a0 commit f9b952f

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

ruby/ql/lib/codeql/ruby/frameworks/stdlib/Pathname.qll

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private import codeql.ruby.DataFlow
77
private import codeql.ruby.dataflow.FlowSummary
88
private import codeql.ruby.dataflow.internal.DataFlowDispatch
99
private import codeql.ruby.frameworks.data.ModelsAsData
10+
private import codeql.ruby.typetracking.TypeTracker
1011

1112
/**
1213
* Modeling of the `Pathname` class from the Ruby standard library.
@@ -31,29 +32,31 @@ module Pathname {
3132
PathnameInstance() { this = pathnameInstance() }
3233
}
3334

34-
private DataFlow::Node pathnameInstance() {
35-
// A call to `Pathname.new`.
36-
result = API::getTopLevelMember("Pathname").getAnInstantiation()
37-
or
38-
// Class methods on `Pathname` that return a new `Pathname`.
39-
result = API::getTopLevelMember("Pathname").getAMethodCall(["getwd", "pwd",])
40-
or
41-
// Instance methods on `Pathname` that return a new `Pathname`.
42-
exists(DataFlow::CallNode c | result = c |
43-
c.getReceiver() = pathnameInstance() and
44-
c.getMethodName() =
45-
[
46-
"+", "/", "basename", "cleanpath", "expand_path", "join", "realpath",
47-
"relative_path_from", "sub", "sub_ext", "to_path"
48-
]
35+
private DataFlow::LocalSourceNode pathnameInstance(TypeTracker t) {
36+
t.start() and
37+
(
38+
// A call to `Pathname.new`.
39+
result = API::getTopLevelMember("Pathname").getAnInstantiation()
40+
or
41+
// Class methods on `Pathname` that return a new `Pathname`.
42+
result = API::getTopLevelMember("Pathname").getAMethodCall(["getwd", "pwd",])
43+
or
44+
// Instance methods on `Pathname` that return a new `Pathname`.
45+
exists(DataFlow::CallNode c | result = c |
46+
c.getReceiver() = pathnameInstance() and
47+
c.getMethodName() =
48+
[
49+
"+", "/", "basename", "cleanpath", "expand_path", "join", "realpath",
50+
"relative_path_from", "sub", "sub_ext", "to_path"
51+
]
52+
)
4953
)
5054
or
51-
exists(DataFlow::Node inst |
52-
inst = pathnameInstance() and
53-
inst.(DataFlow::LocalSourceNode).flowsTo(result)
54-
)
55+
exists(TypeTracker t2 | result = pathnameInstance(t2).track(t2, t))
5556
}
5657

58+
private DataFlow::Node pathnameInstance() { pathnameInstance(TypeTracker::end()).flowsTo(result) }
59+
5760
/** A call where the receiver is a `Pathname`. */
5861
class PathnameCall extends DataFlow::CallNode {
5962
PathnameCall() { this.getReceiver() instanceof PathnameInstance }

0 commit comments

Comments
 (0)