Skip to content

Commit 5812246

Browse files
committed
Rust: Adopt shared flow summaries library
1 parent 46abb90 commit 5812246

File tree

6 files changed

+662
-48
lines changed

6 files changed

+662
-48
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** Provides classes and predicates for defining flow summaries. */
2+
3+
private import rust
4+
// private import DataFlow
5+
private import internal.FlowSummaryImpl as Impl
6+
private import internal.DataFlowImpl
7+
8+
// import all instances below
9+
private module Summaries {
10+
private import codeql.rust.Frameworks
11+
// private import codeql.ruby.frameworks.data.ModelsAsData
12+
}
13+
14+
module LibraryCallable {
15+
/** A callable defined in library code, identified by a unique string. */
16+
abstract class Range extends string {
17+
bindingset[this]
18+
Range() { any() }
19+
20+
/** Gets a call to this library callable. */
21+
CallExprBase getACall() {
22+
exists(Resolvable r, string crate |
23+
r = getCallResolvable(result) and
24+
this = crate + r.getResolvedPath()
25+
|
26+
crate = r.getResolvedCrateOrigin() + "::_::"
27+
or
28+
not r.hasResolvedCrateOrigin() and
29+
crate = ""
30+
)
31+
}
32+
}
33+
}
34+
35+
/** Gets a call to this library callable. */
36+
CallExprBase gesftACall(string s) {
37+
exists(Resolvable r, string crate |
38+
r = getCallResolvable(result) and
39+
s = crate + r.getResolvedPath()
40+
|
41+
crate = r.getResolvedCrateOrigin() + "::"
42+
or
43+
not r.hasResolvedCrateOrigin() and
44+
crate = ""
45+
)
46+
}
47+
48+
final class LibraryCallable = LibraryCallable::Range;
49+
50+
/** A callable with a flow summary, identified by a unique string. */
51+
abstract class SummarizedCallable extends LibraryCallable::Range, Impl::Public::SummarizedCallable {
52+
bindingset[this]
53+
SummarizedCallable() { any() }
54+
55+
override predicate propagatesFlow(
56+
string input, string output, boolean preservesValue, string model
57+
) {
58+
this.propagatesFlow(input, output, preservesValue) and model = ""
59+
}
60+
61+
/**
62+
* Holds if data may flow from `input` to `output` through this callable.
63+
*
64+
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
65+
*/
66+
abstract predicate propagatesFlow(string input, string output, boolean preservesValue);
67+
}

0 commit comments

Comments
 (0)