Skip to content

Commit 395901b

Browse files
committed
Rust: Adopt shared flow summaries library
1 parent 61cb03e commit 395901b

File tree

7 files changed

+658
-41
lines changed

7 files changed

+658
-41
lines changed

rust/ql/lib/codeql/rust/dataflow/DataFlow.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ private import DataFlowImpl::Node as Node
1515
module DataFlow {
1616
final class Node = Node::Node;
1717

18-
final class ParameterNode = Node::ParameterNode;
18+
/**
19+
* The value of a parameter at function entry, viewed as a node in a data
20+
* flow graph.
21+
*/
22+
final class ParameterNode extends Node instanceof Node::SourceParameterNode {
23+
/** Gets the parameter that this node corresponds to. */
24+
ParamBase getParameter() { result = super.getParameter().getParamBase() }
25+
}
1926

2027
final class PostUpdateNode = Node::PostUpdateNode;
2128

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

0 commit comments

Comments
 (0)