C#: Make cs/dereferenced-value-may-be-null a path query

This commit is contained in:
Tom Hvitved
2018-12-05 16:26:24 +01:00
parent e2f271bddb
commit 91e4f7ad83
4 changed files with 972 additions and 120 deletions

View File

@@ -2,7 +2,7 @@
* @name Dereferenced variable may be null
* @description Dereferencing a variable whose value may be 'null' may cause a
* 'NullReferenceException'.
* @kind problem
* @kind path-problem
* @problem.severity warning
* @precision high
* @id cs/dereferenced-value-may-be-null
@@ -14,7 +14,8 @@
import csharp
import semmle.code.csharp.dataflow.Nullness
import PathGraph
from Dereference d, Ssa::SourceVariable v, string msg, Element reason
where d.isFirstMaybeNull(v.getAnSsaDefinition(), msg, reason)
select d, "Variable $@ may be null here " + msg + ".", v, v.toString(), reason, "this"
from Dereference d, PathNode source, PathNode sink, Ssa::SourceVariable v, string msg, Element reason
where d.isFirstMaybeNull(v.getAnSsaDefinition(), source, sink, msg, reason)
select d, source, sink, "Variable $@ may be null here " + msg + ".", v, v.toString(), reason, "this"