Skip to content

Commit b01f81a

Browse files
committed
Use modified getAPath predicate for test
1 parent a1b0f02 commit b01f81a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ module API {
177177
/**
178178
* Gets a path of the given `length` from the root to this node.
179179
*/
180-
string getAPath(int length) {
180+
private string getAPath(int length) {
181181
this instanceof Impl::MkRoot and
182182
length = 0 and
183183
result = ""
@@ -191,7 +191,8 @@ module API {
191191
// avoid producing strings longer than 1MB
192192
result.length() < 1000 * 1000
193193
)
194-
)
194+
) and
195+
length in [1 .. Impl::distanceFromRoot(this)]
195196
}
196197

197198
/** Gets the shortest distance from the root to this node in the API graph. */

ruby/ql/test/library-tests/dataflow/api-graphs/use.ql

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,31 @@ class ApiUseTest extends InlineExpectationsTest {
3737
exists(API::Node a, DataFlow::Node n | relevantNode(a, n, location) |
3838
tag = "use" and
3939
element = n.toString() and
40-
value = a.getAPath(_)
40+
value = getAPath(a, _)
4141
)
4242
}
4343
}
4444

4545
private int size(AstNode n) { not n instanceof StmtSequence and result = count(n.getAChild*()) }
46+
47+
/**
48+
* Gets a path of the given `length` from the root to the given node.
49+
* This is a copy of `API::getAPath()` without the restriction on path length,
50+
* which would otherwise rule out paths involving `getASubclass()`.
51+
*/
52+
string getAPath(API::Node node, int length) {
53+
node instanceof API::Root and
54+
length = 0 and
55+
result = ""
56+
or
57+
exists(API::Node pred, string lbl, string predpath |
58+
pred.getASuccessor(lbl) = node and
59+
lbl != "" and
60+
predpath = getAPath(pred, length - 1) and
61+
exists(string dot | if length = 1 then dot = "" else dot = "." |
62+
result = predpath + dot + lbl and
63+
// avoid producing strings longer than 1MB
64+
result.length() < 1000 * 1000
65+
)
66+
)
67+
}

0 commit comments

Comments
 (0)