mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
C#: Update cs/static/field-written-by-instance to handle properties.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name Static field written by instance method
|
||||
* @description Finds instance methods that write static fields.
|
||||
* @description Finds instance methods and properties that write to static fields.
|
||||
* This is tricky to get right if multiple instances are being manipulated,
|
||||
* and generally bad practice.
|
||||
* @kind problem
|
||||
@@ -14,12 +14,12 @@
|
||||
|
||||
import csharp
|
||||
|
||||
from FieldWrite fw, Field f, Callable m
|
||||
from FieldWrite fw, Field f, Callable c
|
||||
where
|
||||
fw.getTarget() = f and
|
||||
f.isStatic() and
|
||||
m = fw.getEnclosingCallable() and
|
||||
not m.(Member).isStatic() and
|
||||
f.getDeclaringType() = m.getDeclaringType() and
|
||||
m.fromSource()
|
||||
select fw.(VariableAccess), "Write to static field from instance method or constructor."
|
||||
c = fw.getEnclosingCallable() and
|
||||
not exists(Member m | m = c or m = c.(Accessor).getDeclaration() | m.isStatic()) and
|
||||
f.getDeclaringType() = c.getDeclaringType() and
|
||||
c.fromSource()
|
||||
select fw.(VariableAccess), "Write to static field from instance method, property or constructor."
|
||||
|
||||
Reference in New Issue
Block a user