Skip to content

Commit 36eab47

Browse files
committed
C#: Do not assume that extension methods on nullable types do unsafe dereference.
1 parent 0355ea8 commit 36eab47

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,13 @@ class Dereference extends G::DereferenceableExpr {
544544
p.hasExtensionMethodModifier() and
545545
not emc.isConditional()
546546
|
547-
p.fromSource() // assume all non-source extension methods perform a dereference
548-
implies
547+
// Assume all non-source extension methods on
548+
// (1) nullable types are null-safe
549+
// (2) non-nullable types are doing a dereference.
550+
p.fromLibrary() and
551+
not p.getAnnotatedType().isNullableRefType()
552+
or
553+
p.fromSource() and
549554
exists(
550555
Ssa::ImplicitParameterDefinition def,
551556
AssignableDefinitions::ImplicitParameterDefinition pdef

0 commit comments

Comments
 (0)