Skip to content

Commit f76647f

Browse files
committed
Rust: Initial model generation setup
1 parent d6f9eb2 commit f76647f

18 files changed

+422
-5
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ module DataFlow {
1919
* The value of a parameter at function entry, viewed as a node in a data
2020
* flow graph.
2121
*/
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-
}
22+
final class ParameterNode = Node::SourceParameterNode;
2623

2724
final class PostUpdateNode = Node::PostUpdateNode;
2825

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ module Node {
145145
*/
146146
ExprCfgNode asExpr() { none() }
147147

148+
/**
149+
* Gets the parameter that corresponds to this node, if any.
150+
*/
151+
ParamBase asParameter() { result = this.(SourceParameterNode).getParameter().getParamBase() }
152+
148153
/**
149154
* Gets the pattern that corresponds to this node, if any.
150155
*/
@@ -273,6 +278,7 @@ module Node {
273278
* flow graph.
274279
*/
275280
abstract class ParameterNode extends Node {
281+
/** Holds if this node is a parameter of `c` at position `pos`. */
276282
abstract predicate isParameterOf(DataFlowCallable c, ParameterPosition pos);
277283
}
278284

@@ -726,7 +732,7 @@ class StructCanonicalPath extends MkStructCanonicalPath {
726732
}
727733

728734
/** Content stored in a field on a struct. */
729-
private class StructFieldContent extends Content, TStructFieldContent {
735+
final class StructFieldContent extends Content, TStructFieldContent {
730736
private StructCanonicalPath s;
731737
private string field_;
732738

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture content based summary models.
3+
* @description Finds applicable content based summary models to be used by other queries.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/contentbased-summary-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string flow
12+
where flow = ContentSensitive::captureFlow(api, _)
13+
select flow order by flow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture mixed neutral models.
3+
* @description Finds neutral models to be used by other queries.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/mixed-neutral-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string noflow
12+
where noflow = captureMixedNeutral(api)
13+
select noflow order by noflow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture mixed summary models.
3+
* @description Finds applicable summary models to be used by other queries.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/mixed-summary-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string flow
12+
where flow = captureMixedFlow(api, _)
13+
select flow order by flow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture neutral models.
3+
* @description Finds neutral models to be used by other queries.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/neutral-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string noflow
12+
where noflow = captureNoFlow(api)
13+
select noflow order by noflow
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture sink models.
3+
* @description Finds public methods that act as sinks as they flow into a known sink.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/sink-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSinkTargetApi api, string sink
12+
where sink = captureSink(api)
13+
select sink order by sink
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture source models.
3+
* @description Finds APIs that act as sources as they expose already known sources.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/source-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSourceTargetApi api, string source
12+
where source = captureSource(api)
13+
select source order by source
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @name Capture summary models.
3+
* @description Finds applicable summary models to be used by other queries.
4+
* @kind diagnostic
5+
* @id rust/utils/modelgenerator/summary-models
6+
* @tags modelgenerator
7+
*/
8+
9+
import internal.CaptureModels
10+
11+
from DataFlowSummaryTargetApi api, string flow
12+
where flow = captureFlow(api)
13+
select flow order by flow
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import os.path
5+
import subprocess
6+
7+
# Add Model as Data script directory to sys.path.
8+
gitroot = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
9+
madpath = os.path.join(gitroot, "misc/scripts/models-as-data/")
10+
sys.path.append(madpath)
11+
12+
import generate_flow_model as model
13+
14+
language = "rust"
15+
model.Generator.make(language).run()

0 commit comments

Comments
 (0)