Skip to content

Commit 503830a

Browse files
committedNov 28, 2024·
Implement Concurrency8 package
·
v2.47.0v2.42.0
1 parent 5c5bb64 commit 503830a

File tree

56 files changed

+1964
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1964
-209
lines changed
 

‎c/cert/src/rules/CON34-C/AppropriateThreadObjectStorageDurations.ql

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,39 @@
1414

1515
import cpp
1616
import codingstandards.c.cert
17+
import codingstandards.c.Objects
1718
import codingstandards.cpp.Concurrency
1819
import codingstandards.cpp.dataflow.TaintTracking
1920
import codingstandards.cpp.dataflow.DataFlow
2021
import semmle.code.cpp.commons.Alloc
2122

22-
from C11ThreadCreateCall tcc, StackVariable sv, Expr arg, Expr acc
23+
from C11ThreadCreateCall tcc, Expr arg
2324
where
2425
not isExcluded(tcc, Concurrency4Package::appropriateThreadObjectStorageDurationsQuery()) and
2526
tcc.getArgument(2) = arg and
26-
sv.getAnAccess() = acc and
27-
// a stack variable that is given as an argument to a thread
28-
TaintTracking::localTaint(DataFlow::exprNode(acc), DataFlow::exprNode(arg)) and
29-
// or isn't one of the allowed usage patterns
30-
not exists(Expr mfc |
31-
isAllocationExpr(mfc) and
32-
sv.getAnAssignedValue() = mfc and
33-
acc.getAPredecessor*() = mfc
34-
) and
35-
not exists(TSSGetFunctionCall tsg, TSSSetFunctionCall tss, DataFlow::Node src |
36-
sv.getAnAssignedValue() = tsg and
37-
acc.getAPredecessor*() = tsg and
38-
// there should be dataflow from somewhere (the same somewhere)
39-
// into each of the first arguments
40-
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
41-
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
27+
(
28+
exists(ObjectIdentity obj, Expr acc |
29+
obj.getASubobjectAccess() = acc and
30+
obj.getStorageDuration().isAutomatic() and
31+
exists(DataFlow::Node addrNode |
32+
(
33+
addrNode = DataFlow::exprNode(any(AddressOfExpr e | e.getOperand() = acc))
34+
or
35+
addrNode = DataFlow::exprNode(acc) and exists(ArrayToPointerConversion c | c.getExpr() = acc)
36+
) and
37+
TaintTracking::localTaint(addrNode, DataFlow::exprNode(arg))
38+
)
39+
)
40+
or
41+
// TODO: Remove/replace with tss_t type check, see #801.
42+
exists(TSSGetFunctionCall tsg |
43+
TaintTracking::localTaint(DataFlow::exprNode(tsg), DataFlow::exprNode(arg)) and
44+
not exists(TSSSetFunctionCall tss, DataFlow::Node src |
45+
// there should be dataflow from somewhere (the same somewhere)
46+
// into each of the first arguments
47+
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
48+
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
49+
)
50+
)
4251
)
4352
select tcc, "$@ not declared with appropriate storage duration", arg, "Shared object"

‎c/cert/src/rules/DCL30-C/AppropriateStorageDurationsFunctionReturn.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16+
import codingstandards.c.Objects
1617
import codingstandards.cpp.dataflow.DataFlow
1718

18-
class Source extends StackVariable {
19-
Source() { not this instanceof Parameter }
19+
class Source extends Expr {
20+
ObjectIdentity rootObject;
21+
Source() {
22+
rootObject.getStorageDuration().isAutomatic()
23+
and this = rootObject.getASubobjectAddressExpr()
24+
}
2025
}
2126

2227
class Sink extends DataFlow::Node {
@@ -40,7 +45,7 @@ from DataFlow::Node src, DataFlow::Node sink
4045
where
4146
not isExcluded(sink.asExpr(),
4247
Declarations8Package::appropriateStorageDurationsFunctionReturnQuery()) and
43-
exists(Source s | src.asExpr() = s.getAnAccess()) and
48+
exists(Source s | src.asExpr() = s) and
4449
sink instanceof Sink and
4550
DataFlow::localFlow(src, sink)
4651
select sink, "$@ with automatic storage may be accessible outside of its lifetime.", src,

0 commit comments

Comments
 (0)
Please sign in to comment.