Skip to content

Commit 0a846c7

Browse files
committed
Convert CON34-C to the new dataflow library
Since the new dataflow library uses use-use dataflow and not def-use dataflow, we now need to check for definitions. Note that these queries can probably be improved by using a dataflow configuration - possibly limited to the local context of a function by including `DataFlow::FeatureEqualSourceSinkCallContext`
1 parent 22b8860 commit 0a846c7

File tree

4 files changed

+7
-23
lines changed

4 files changed

+7
-23
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import cpp
2121
import codingstandards.c.cert
2222
import codingstandards.c.Objects
23-
import codingstandards.cpp.Concurrency
24-
import semmle.code.cpp.dataflow.DataFlow
23+
import codingstandards.cpp.ConcurrencyNew
24+
import semmle.code.cpp.dataflow.new.DataFlow
2525
import semmle.code.cpp.commons.Alloc
2626

2727
from C11ThreadCreateCall tcc, Expr arg
@@ -53,6 +53,7 @@ where
5353
not exists(TSSSetFunctionCall tss, DataFlow::Node src |
5454
// there should be dataflow from somewhere (the same somewhere)
5555
// into each of the first arguments
56+
exists(Expr e | e = src.asDefinition() or e = src.asDefiningArgument()) and
5657
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
5758
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
5859
)

c/cert/src/rules/CON34-C/ThreadObjectStorageDurationsNotInitialized.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import cpp
2222
import codingstandards.c.cert
23-
import codingstandards.cpp.Concurrency
24-
import semmle.code.cpp.dataflow.DataFlow
23+
import codingstandards.cpp.ConcurrencyNew
24+
import semmle.code.cpp.dataflow.new.DataFlow
2525

2626
from TSSGetFunctionCall tsg, ThreadedFunction tf
2727
where
@@ -31,7 +31,8 @@ where
3131
// however, there does not exist a proper sequencing.
3232
not exists(TSSSetFunctionCall tss, DataFlow::Node src |
3333
// there should be dataflow from somewhere (the same somewhere)
34-
// into each of the first arguments
34+
// into each of the first argument
35+
exists(Expr e | e = src.asDefinition() or e = src.asDefiningArgument()) and
3536
DataFlow::localFlow(src, DataFlow::exprNode(tsg.getArgument(0))) and
3637
DataFlow::localFlow(src, DataFlow::exprNode(tss.getArgument(0)))
3738
)

c/cert/test/rules/CON34-C/AppropriateThreadObjectStorageDurations.expected

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:35,14-22)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:37,22-30)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:39,22-30)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:42,45-53)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:52,33-41)
6-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:52,58-66)
7-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:53,42-50)
8-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:56,9-17)
9-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:56,34-42)
10-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:57,9-17)
11-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:57,34-42)
12-
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:42,9-22)
13-
WARNING: module 'TaintTracking' has been deprecated and may be removed in future (AppropriateThreadObjectStorageDurations.ql:52,7-20)
141
| test.c:23:3:23:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:23:24:23:29 | & ... | Shared object |
152
| test.c:74:3:74:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:74:24:74:24 | p | Shared object |
163
| test.c:85:3:85:13 | call to thrd_create | $@ not declared with appropriate storage duration | test.c:85:24:85:24 | p | Shared object |
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ThreadObjectStorageDurationsNotInitialized.ql:32,38-46)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ThreadObjectStorageDurationsNotInitialized.ql:35,5-13)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ThreadObjectStorageDurationsNotInitialized.ql:35,30-38)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ThreadObjectStorageDurationsNotInitialized.ql:36,5-13)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (ThreadObjectStorageDurationsNotInitialized.ql:36,30-38)
61
| test.c:14:7:14:13 | call to tss_get | Call to a thread specific storage function from within a threaded context on an object that may not be owned by this thread. |

0 commit comments

Comments
 (0)