mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Java/Shared: Share more 'isNull' computations.
This commit is contained in:
@@ -125,7 +125,7 @@ private module Input implements TypeFlowInput<J::Location> {
|
||||
/**
|
||||
* Holds if `null` is the only value that flows to `n`.
|
||||
*/
|
||||
predicate isNull(TypeFlowNode n) {
|
||||
predicate isNullValue(TypeFlowNode n) {
|
||||
n.asExpr() instanceof NullLiteral
|
||||
or
|
||||
exists(LocalVariableDeclExpr decl |
|
||||
@@ -134,9 +134,7 @@ private module Input implements TypeFlowInput<J::Location> {
|
||||
not exists(decl.getInit())
|
||||
)
|
||||
or
|
||||
exists(TypeFlowNode mid | isNull(mid) and step(mid, n))
|
||||
or
|
||||
forex(TypeFlowNode mid | joinStep0(mid, n) | isNull(mid)) and
|
||||
forex(TypeFlowNode mid | joinStep0(mid, n) | Make<J::Location, Input>::isNull(mid)) and
|
||||
// Fields that are never assigned a non-null value are probably set by
|
||||
// reflection and are thus not always null.
|
||||
not exists(n.asField())
|
||||
|
||||
@@ -39,10 +39,8 @@ signature module TypeFlowInput<LocationSig Location> {
|
||||
*/
|
||||
predicate step(TypeFlowNode n1, TypeFlowNode n2);
|
||||
|
||||
/**
|
||||
* Holds if `null` is the only value that flows to `n`.
|
||||
*/
|
||||
predicate isNull(TypeFlowNode n);
|
||||
/** Holds if `n` represents a `null` value. */
|
||||
predicate isNullValue(TypeFlowNode n);
|
||||
|
||||
/** A type. */
|
||||
class Type {
|
||||
|
||||
@@ -5,6 +5,13 @@ private import codeql.util.Unit
|
||||
module TypeFlow<LocationSig Location, TypeFlowInput<Location> I> {
|
||||
private import I
|
||||
|
||||
/** Holds if `null` is the only value that flows to `n`. */
|
||||
predicate isNull(TypeFlowNode n) {
|
||||
isNullValue(n)
|
||||
or
|
||||
exists(TypeFlowNode mid | isNull(mid) and step(mid, n))
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if data can flow from `n1` to `n2` in one step, `n1` is not necessarily
|
||||
* functionally determined by `n2`, and `n1` might take a non-null value.
|
||||
|
||||
Reference in New Issue
Block a user