mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: Exclude data flow inconsistencies that stem from other inconsistencies
This commit is contained in:
@@ -5,12 +5,4 @@
|
||||
* @id rust/diagnostics/data-flow-consistency
|
||||
*/
|
||||
|
||||
import codeql.rust.dataflow.DataFlow::DataFlow as DataFlow
|
||||
private import rust
|
||||
private import codeql.rust.dataflow.internal.DataFlowImpl
|
||||
private import codeql.rust.dataflow.internal.TaintTrackingImpl
|
||||
private import codeql.dataflow.internal.DataFlowImplConsistency
|
||||
|
||||
private module Input implements InputSig<Location, RustDataFlow> { }
|
||||
|
||||
import MakeConsistency<Location, RustDataFlow, RustTaintTracking, Input>
|
||||
import codeql.rust.dataflow.internal.DataFlowConsistency
|
||||
|
||||
@@ -21,6 +21,11 @@ query predicate multipleToStrings(Element e, string cls, string s) {
|
||||
*/
|
||||
query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) > 1 }
|
||||
|
||||
/**
|
||||
* Holds if `e` does not have a `Location`.
|
||||
*/
|
||||
query predicate noLocation(Locatable e) { not exists(e.getLocation()) }
|
||||
|
||||
private predicate multiplePrimaryQlClasses(Element e) {
|
||||
strictcount(string cls | cls = e.getAPrimaryQlClass() and cls != "VariableAccess") > 1
|
||||
}
|
||||
@@ -58,6 +63,9 @@ int getAstInconsistencyCounts(string type) {
|
||||
type = "Multiple locations" and
|
||||
result = count(Element e | multipleLocations(e) | e)
|
||||
or
|
||||
type = "No location" and
|
||||
result = count(Element e | noLocation(e) | e)
|
||||
or
|
||||
type = "Multiple primary QL classes" and
|
||||
result = count(Element e | multiplePrimaryQlClasses(e) | e)
|
||||
or
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import codeql.rust.dataflow.DataFlow::DataFlow as DataFlow
|
||||
private import rust
|
||||
private import codeql.rust.dataflow.internal.DataFlowImpl
|
||||
private import codeql.rust.dataflow.internal.TaintTrackingImpl
|
||||
private import codeql.dataflow.internal.DataFlowImplConsistency
|
||||
|
||||
private module Input implements InputSig<Location, RustDataFlow> {
|
||||
predicate uniqueNodeLocationExclude(RustDataFlow::Node n) {
|
||||
// Exclude nodes where the missing location can be explained by the
|
||||
// underlying AST node not having a location.
|
||||
not exists(n.asExpr().getLocation())
|
||||
}
|
||||
|
||||
predicate missingLocationExclude(RustDataFlow::Node n) { not exists(n.asExpr().getLocation()) }
|
||||
}
|
||||
|
||||
import MakeConsistency<Location, RustDataFlow, RustTaintTracking, Input>
|
||||
@@ -5,17 +5,10 @@
|
||||
* @id rust/diagnostics/data-flow-consistency-counts
|
||||
*/
|
||||
|
||||
private import rust
|
||||
private import codeql.rust.dataflow.internal.DataFlowImpl
|
||||
private import codeql.rust.dataflow.internal.TaintTrackingImpl
|
||||
private import codeql.dataflow.internal.DataFlowImplConsistency
|
||||
|
||||
private module Input implements InputSig<Location, RustDataFlow> { }
|
||||
import codeql.rust.dataflow.internal.DataFlowConsistency as Consistency
|
||||
|
||||
// see also `rust/diagnostics/data-flow-consistency`, which lists the
|
||||
// individual inconsistency results.
|
||||
from string type, int num
|
||||
where
|
||||
num =
|
||||
MakeConsistency<Location, RustDataFlow, RustTaintTracking, Input>::getInconsistencyCounts(type)
|
||||
where num = Consistency::getInconsistencyCounts(type)
|
||||
select type, num
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
noLocation
|
||||
| file://:0:0:0:0 | ... .parent(...) |
|
||||
| file://:0:0:0:0 | ... .unwrap(...) |
|
||||
| file://:0:0:0:0 | ...: ... |
|
||||
| file://:0:0:0:0 | ...::Path |
|
||||
| file://:0:0:0:0 | ...::path |
|
||||
| file://:0:0:0:0 | ArgList |
|
||||
| file://:0:0:0:0 | ArgList |
|
||||
| file://:0:0:0:0 | MacroItems |
|
||||
| file://:0:0:0:0 | ParamList |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | Path |
|
||||
| file://:0:0:0:0 | RefType |
|
||||
| file://:0:0:0:0 | RefType |
|
||||
| file://:0:0:0:0 | RetType |
|
||||
| file://:0:0:0:0 | StmtList |
|
||||
| file://:0:0:0:0 | Use |
|
||||
| file://:0:0:0:0 | UseTree |
|
||||
| file://:0:0:0:0 | fn get_parent |
|
||||
| file://:0:0:0:0 | get_parent |
|
||||
| file://:0:0:0:0 | parent |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | path |
|
||||
| file://:0:0:0:0 | std |
|
||||
| file://:0:0:0:0 | std |
|
||||
| file://:0:0:0:0 | std |
|
||||
| file://:0:0:0:0 | unwrap |
|
||||
| file://:0:0:0:0 | { ... } |
|
||||
@@ -1,11 +0,0 @@
|
||||
uniqueNodeLocation
|
||||
| file://:0:0:0:0 | ... .parent(...) | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | ... .parent(...) | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | ... .unwrap(...) | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | ...: ... | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | path | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | path | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | path | Node should have one location but has 0. |
|
||||
| file://:0:0:0:0 | { ... } | Node should have one location but has 0. |
|
||||
missingLocation
|
||||
| Nodes without location: 8 |
|
||||
@@ -2,3 +2,4 @@
|
||||
| Multiple parents | 0 |
|
||||
| Multiple primary QL classes | 0 |
|
||||
| Multiple toStrings | 0 |
|
||||
| No location | 0 |
|
||||
|
||||
Reference in New Issue
Block a user