forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadLocalObjectAddressCopiedToGlobalObject.ql
More file actions
39 lines (37 loc) · 1.51 KB
/
ThreadLocalObjectAddressCopiedToGlobalObject.ql
File metadata and controls
39 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @id c/misra/thread-local-object-address-copied-to-global-object
* @name RULE-18-6: The address of an object with thread-local storage shall not be copied to a global object
* @description Storing the address of a thread-local object in a global object will result in
* undefined behavior if the address is accessed after the relevant thread is
* terminated.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/rule-18-6
* correctness
* external/misra/c/2012/amendment3
* external/misra/obligation/required
*/
import cpp
import codingstandards.c.misra
import codingstandards.c.Objects
import codingstandards.cpp.ConcurrencyNew
from AssignExpr assignment, Element threadLocal, ObjectIdentity static
where
not isExcluded(assignment, Pointers1Package::threadLocalObjectAddressCopiedToGlobalObjectQuery()) and
assignment.getLValue() = static.getASubobjectAccess() and
static.getStorageDuration().isStatic() and
(
exists(ObjectIdentity threadLocalObj |
threadLocal = threadLocalObj and
assignment.getRValue() = threadLocalObj.getASubobjectAddressExpr() and
threadLocalObj.getStorageDuration().isThread()
)
or
exists(TSSGetFunctionCall getCall |
threadLocal = getCall.getKey() and
assignment.getRValue() = getCall
)
)
select assignment, "Thread local object $@ address copied to static object $@.",
threadLocal.getLocation(), threadLocal.toString(), static.getLocation(), static.toString()