mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Replace references to getANullCheck.
This commit is contained in:
@@ -776,6 +776,17 @@ class DereferenceableExpr extends Expr {
|
||||
or
|
||||
result = this.getANullnessNullCheck(v, isNull)
|
||||
}
|
||||
|
||||
/** Holds if `guard` suggests that this expression may be `null`. */
|
||||
predicate guardSuggestsMaybeNull(Guards::Guard guard) {
|
||||
guard = this.getANullnessNullCheck(_, true)
|
||||
or
|
||||
LogicInput::additionalNullCheck(guard, _, this, true)
|
||||
or
|
||||
guard.isEquality(this, any(Expr n | nullValueImplied(n)), _)
|
||||
or
|
||||
Guards::nullGuard(guard, any(GuardValue v | exists(v.asBooleanValue())), this, true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -193,7 +193,7 @@ private predicate defMaybeNull(
|
||||
(
|
||||
// A variable compared to `null` might be `null`
|
||||
exists(G::DereferenceableExpr de | de = def.getARead() |
|
||||
reason = de.getANullCheck(_, true) and
|
||||
de.guardSuggestsMaybeNull(reason) and
|
||||
msg = "as suggested by $@ null check" and
|
||||
node = def.getControlFlowNode() and
|
||||
not de = any(Ssa::PhiNode phi).getARead() and
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
| C.cs:45:22:45:30 | ... != ... | C.cs:45:22:45:22 | access to local variable s |
|
||||
| C.cs:56:23:56:24 | access to local variable o2 | C.cs:56:23:56:24 | access to local variable o2 |
|
||||
| C.cs:71:26:71:27 | access to local variable o3 | C.cs:71:26:71:27 | access to local variable o3 |
|
||||
| C.cs:78:13:78:24 | call to method IsNotNull | C.cs:78:23:78:23 | access to local variable o |
|
||||
| C.cs:81:14:81:22 | call to method IsNull | C.cs:81:21:81:21 | access to local variable o |
|
||||
| C.cs:113:22:113:36 | ... == ... | C.cs:113:22:113:28 | access to local variable colours |
|
||||
| C.cs:113:22:113:36 | ... == ... | C.cs:113:33:113:36 | null |
|
||||
| C.cs:120:13:120:28 | ... == ... | C.cs:120:13:120:20 | access to local variable children |
|
||||
@@ -144,8 +142,7 @@
|
||||
| E.cs:422:13:422:22 | access to property HasValue | E.cs:422:13:422:13 | access to parameter i |
|
||||
| E.cs:429:13:429:22 | access to property HasValue | E.cs:429:13:429:13 | access to parameter i |
|
||||
| E.cs:437:23:437:31 | ... is ... | E.cs:437:23:437:23 | access to parameter s |
|
||||
| Forwarding.cs:19:14:19:23 | call to method IsNull | Forwarding.cs:19:14:19:14 | access to local variable s |
|
||||
| Forwarding.cs:24:13:24:25 | call to method IsNotNull | Forwarding.cs:24:13:24:13 | access to local variable s |
|
||||
| E.cs:447:23:447:35 | ... is ... | E.cs:447:23:447:23 | access to parameter s |
|
||||
| Forwarding.cs:45:66:45:75 | call to method IsNull | Forwarding.cs:45:66:45:66 | access to parameter o |
|
||||
| Forwarding.cs:59:13:59:21 | ... == ... | Forwarding.cs:59:13:59:13 | access to parameter o |
|
||||
| Forwarding.cs:78:16:78:39 | call to method ReferenceEquals | Forwarding.cs:78:32:78:32 | access to parameter o |
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.controlflow.Guards
|
||||
|
||||
from DereferenceableExpr de
|
||||
select de.getANullCheck(_, true), de
|
||||
from DereferenceableExpr de, Guards::Guard reason
|
||||
where de.guardSuggestsMaybeNull(reason)
|
||||
select reason, de
|
||||
|
||||
@@ -57,7 +57,9 @@
|
||||
| E.cs:423:38:423:38 | access to parameter i | Variable $@ may be null at this access because it has a nullable type. | E.cs:420:27:420:27 | i | i | E.cs:420:27:420:27 | i | this |
|
||||
| E.cs:430:39:430:39 | access to parameter i | Variable $@ may be null at this access because it has a nullable type. | E.cs:427:27:427:27 | i | i | E.cs:427:27:427:27 | i | this |
|
||||
| E.cs:444:13:444:13 | access to parameter s | Variable $@ may be null at this access as suggested by $@ null check. | E.cs:435:29:435:29 | s | s | E.cs:437:23:437:31 | ... is ... | this |
|
||||
| E.cs:444:13:444:13 | access to parameter s | Variable $@ may be null at this access as suggested by $@ null check. | E.cs:435:29:435:29 | s | s | E.cs:447:23:447:35 | ... is ... | this |
|
||||
| E.cs:459:13:459:13 | access to parameter s | Variable $@ may be null at this access as suggested by $@ null check. | E.cs:435:29:435:29 | s | s | E.cs:437:23:437:31 | ... is ... | this |
|
||||
| E.cs:459:13:459:13 | access to parameter s | Variable $@ may be null at this access as suggested by $@ null check. | E.cs:435:29:435:29 | s | s | E.cs:447:23:447:35 | ... is ... | this |
|
||||
| GuardedString.cs:35:31:35:31 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | GuardedString.cs:7:16:7:16 | s | s | GuardedString.cs:7:16:7:32 | String s = ... | this |
|
||||
| NullMaybeBad.cs:7:27:7:27 | access to parameter o | Variable $@ may be null at this access because of $@ null argument. | NullMaybeBad.cs:5:25:5:25 | o | o | NullMaybeBad.cs:13:17:13:20 | null | this |
|
||||
| Params.cs:14:17:14:20 | access to parameter args | Variable $@ may be null at this access because of $@ null argument. | Params.cs:12:36:12:39 | args | args | Params.cs:20:12:20:15 | null | this |
|
||||
|
||||
Reference in New Issue
Block a user