and consistency query that will highlight new consistency errors

This commit is contained in:
Erik Krogh Kristensen
2021-10-16 23:17:42 +02:00
parent 74b1c19a20
commit 9d9663d842
2 changed files with 42 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import ql
import codeql_ql.ast.internal.AstNodes
private import codeql_ql.ast.internal.AstNodes
private class TScope =
TClass or TAggregate or TQuantifier or TSelect or TPredicate or TNewTypeBranch;
@@ -89,4 +89,8 @@ module VarConsistency {
decl = f.getDeclaration() and
strictcount(f.getDeclaration()) > 1
}
query predicate noFieldDef(FieldAccess f) { not exists(f.getDeclaration()) }
query predicate noVarDef(VarAccess v) { not exists(v.getDeclaration()) }
}

View File

@@ -0,0 +1,37 @@
/**
* @name Consistency predicate that should be empty
* @description This query should have no results on the CodeQL repos.
* It's marked as a warning query to make the results visible.
* @kind problem
* @problem.severity warning
* @precision very-high
* @id ql/diagnostics/empty-consitencies
*/
import ql
import codeql_ql.ast.internal.Predicate::PredConsistency as PredConsistency
import codeql_ql.ast.internal.Type::TyConsistency as TypeConsistency
import codeql_ql.ast.internal.Builtins::BuildinsConsistency as BuildinsConsistency
import codeql_ql.ast.internal.Module::ModConsistency as ModConsistency
import codeql_ql.ast.internal.Variable::VarConsistency as VarConsistency
from AstNode node, string msg
where
PredConsistency::noResolveCall(node) and msg = "PredConsistency::noResolveCall"
or
TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
or
TypeConsistency::exprNoType(node) and msg = "TypeConsistency::exprNoType"
or
TypeConsistency::varDefNoType(node) and msg = "TypeConsistency::varDefNoType"
or
//or // has 1 result, but the CodeQL compiler also can't figure out that one. I suppoed the file is never imported.
//TypeConsistency::noResolve(node) and msg = "TypeConsistency::noResolve"
//or // has 1 result, but the CodeQL compiler also can't figure out that one. Same file as above.
//ModConsistency::noResolve(node) and msg = "ModConsistency::noResolve"
ModConsistency::noResolveModuleExpr(node) and msg = "ModConsistency::noResolveModuleExpr"
or
VarConsistency::noFieldDef(node) and msg = "VarConsistency::noFieldDef"
or
VarConsistency::noVarDef(node) and msg = "VarConsistency::noVarDef"
select node, msg