Files
codeql/csharp/ql/src/Concurrency/LockedWait.ql
2025-06-17 09:56:43 +02:00

36 lines
948 B
Plaintext

/**
* @name A lock is held during a wait
* @description A lock is held during a call to System.Threading.Monitor.Wait(). This can lead to deadlocks and performance problems.
* @kind problem
* @problem.severity warning
* @precision high
* @id cs/locked-wait
* @tags quality
* reliability
* concurrency
* correctness
* external/cwe/cwe-662
* external/cwe/cwe-833
*/
import csharp
import Concurrency
from LockedBlock l, WaitStmt w, string lockedItem
where
l.getALockedStmt() = w and
(
exists(Variable v |
v = l.getLockVariable() and not v = w.getWaitVariable() and lockedItem = v.getName()
)
or
exists(Type t |
t = l.getLockTypeObject() and
not t = w.getWaitTypeObject() and
lockedItem = "typeof(" + t.getName() + ")"
)
or
l.isLockThis() and not w.isWaitThis() and lockedItem = "this"
)
select w, "'" + lockedItem + "' is locked during this wait."