Skip to content

Commit 32e2c19

Browse files
committed
Rust: Move all summary stats logic into Stats.qll.
1 parent ff2a1ca commit 32e2c19

File tree

2 files changed

+92
-81
lines changed

2 files changed

+92
-81
lines changed

rust/ql/src/queries/summary/Stats.qll

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ private import codeql.rust.internal.PathResolutionConsistency as PathResolutionC
1111
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
1212
private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
1313
private import codeql.rust.Concepts
14+
private import codeql.rust.Diagnostics
15+
private import codeql.rust.security.SensitiveData
16+
private import TaintReach
1417
// import all query extensions files, so that all extensions of `QuerySink` are found
1518
private import codeql.rust.security.CleartextLoggingExtensions
1619
private import codeql.rust.security.SqlInjectionExtensions
@@ -72,3 +75,92 @@ int getTaintEdgesCount() {
7275
* Gets a count of the total number of query sinks in the database.
7376
*/
7477
int getQuerySinksCount() { result = count(QuerySink s) }
78+
79+
class CrateElement extends Element {
80+
CrateElement() {
81+
this instanceof Crate or
82+
this instanceof NamedCrate or
83+
this.(AstNode).getParentNode*() = any(Crate c).getModule()
84+
}
85+
}
86+
87+
/**
88+
* Gets summary statistics about individual elements in the database.
89+
*/
90+
predicate elementStats(string key, int value) {
91+
key = "Elements extracted" and
92+
value = count(Element e | not e instanceof Unextracted and not e instanceof CrateElement)
93+
or
94+
key = "Elements unextracted" and value = count(Unextracted e)
95+
}
96+
97+
/**
98+
* Gets summary statistics about extraction.
99+
*/
100+
predicate extractionStats(string key, int value) {
101+
key = "Extraction errors" and value = count(ExtractionError e)
102+
or
103+
key = "Extraction warnings" and value = count(ExtractionWarning w)
104+
or
105+
key = "Files extracted - total" and value = count(ExtractedFile f | exists(f.getRelativePath()))
106+
or
107+
key = "Files extracted - with errors" and
108+
value =
109+
count(ExtractedFile f |
110+
exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile
111+
)
112+
or
113+
key = "Files extracted - without errors" and
114+
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
115+
or
116+
key = "Files extracted - without errors %" and
117+
value =
118+
(count(SuccessfullyExtractedFile f | exists(f.getRelativePath())) * 100) /
119+
count(ExtractedFile f | exists(f.getRelativePath()))
120+
or
121+
key = "Lines of code extracted" and value = getLinesOfCode()
122+
or
123+
key = "Lines of user code extracted" and value = getLinesOfUserCode()
124+
or
125+
key = "Macro calls - total" and value = count(MacroCall mc)
126+
or
127+
key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded())
128+
or
129+
key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded())
130+
}
131+
132+
/**
133+
* Gets summary statistics about inconsistencies.
134+
*/
135+
predicate inconsistencyStats(string key, int value) {
136+
key = "Inconsistencies - AST" and value = getTotalAstInconsistencies()
137+
or
138+
key = "Inconsistencies - Path resolution" and value = getTotalPathResolutionInconsistencies()
139+
or
140+
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
141+
or
142+
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
143+
}
144+
145+
/**
146+
* Gets summary statistics about taint.
147+
*/
148+
predicate taintStats(string key, int value) {
149+
key = "Taint sources - active" and value = count(ActiveThreatModelSource s)
150+
or
151+
key = "Taint sources - disabled" and
152+
value = count(ThreatModelSource s | not s instanceof ActiveThreatModelSource)
153+
or
154+
key = "Taint sources - sensitive data" and value = count(SensitiveData d)
155+
or
156+
key = "Taint edges - number of edges" and value = getTaintEdgesCount()
157+
or
158+
key = "Taint reach - nodes tainted" and value = getTaintedNodesCount()
159+
or
160+
key = "Taint reach - per million nodes" and value = getTaintReach().floor()
161+
or
162+
key = "Taint sinks - query sinks" and value = getQuerySinksCount()
163+
or
164+
key = "Taint sinks - cryptographic operations" and
165+
value = count(Cryptography::CryptographicOperation o)
166+
}

rust/ql/src/queries/summary/SummaryStats.ql

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,88 +7,7 @@
77
*/
88

99
import rust
10-
import codeql.rust.Concepts
11-
import codeql.rust.security.SensitiveData
12-
import codeql.rust.Diagnostics
1310
import Stats
14-
import TaintReach
15-
16-
class CrateElement extends Element {
17-
CrateElement() {
18-
this instanceof Crate or
19-
this instanceof NamedCrate or
20-
this.(AstNode).getParentNode*() = any(Crate c).getModule()
21-
}
22-
}
23-
24-
predicate elementStats(string key, int value) {
25-
key = "Elements extracted" and
26-
value = count(Element e | not e instanceof Unextracted and not e instanceof CrateElement)
27-
or
28-
key = "Elements unextracted" and value = count(Unextracted e)
29-
}
30-
31-
predicate extractionStats(string key, int value) {
32-
key = "Extraction errors" and value = count(ExtractionError e)
33-
or
34-
key = "Extraction warnings" and value = count(ExtractionWarning w)
35-
or
36-
key = "Files extracted - total" and value = count(ExtractedFile f | exists(f.getRelativePath()))
37-
or
38-
key = "Files extracted - with errors" and
39-
value =
40-
count(ExtractedFile f |
41-
exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile
42-
)
43-
or
44-
key = "Files extracted - without errors" and
45-
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
46-
or
47-
key = "Files extracted - without errors %" and
48-
value =
49-
(count(SuccessfullyExtractedFile f | exists(f.getRelativePath())) * 100) /
50-
count(ExtractedFile f | exists(f.getRelativePath()))
51-
or
52-
key = "Lines of code extracted" and value = getLinesOfCode()
53-
or
54-
key = "Lines of user code extracted" and value = getLinesOfUserCode()
55-
or
56-
key = "Macro calls - total" and value = count(MacroCall mc)
57-
or
58-
key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded())
59-
or
60-
key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded())
61-
}
62-
63-
predicate inconsistencyStats(string key, int value) {
64-
key = "Inconsistencies - AST" and value = getTotalAstInconsistencies()
65-
or
66-
key = "Inconsistencies - Path resolution" and value = getTotalPathResolutionInconsistencies()
67-
or
68-
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
69-
or
70-
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
71-
}
72-
73-
predicate taintStats(string key, int value) {
74-
key = "Taint sources - active" and value = count(ActiveThreatModelSource s)
75-
or
76-
key = "Taint sources - disabled" and
77-
value = count(ThreatModelSource s | not s instanceof ActiveThreatModelSource)
78-
or
79-
key = "Taint sources - sensitive data" and value = count(SensitiveData d)
80-
or
81-
key = "Taint edges - number of edges" and value = getTaintEdgesCount()
82-
or
83-
key = "Taint reach - nodes tainted" and value = getTaintedNodesCount()
84-
or
85-
key = "Taint reach - per million nodes" and value = getTaintReach().floor()
86-
or
87-
key = "Taint sinks - query sinks" and value = getQuerySinksCount()
88-
or
89-
key = "Taint sinks - cryptographic operations" and
90-
value = count(Cryptography::CryptographicOperation o)
91-
}
9211

9312
from string key, int value
9413
where

0 commit comments

Comments
 (0)