Skip to content

Commit cf1b625

Browse files
committed
Conver ARR39-C to the new dataflow library
Observe that `sizeof(...)` might not occur as a dataflow node if it has a parent node with a concrete value. That value will be a dataflow node instead. Hence, the query has be changed to check for expressions where `sizeof(...)` is a child of an expression with a concrete value.
1 parent 2089bcd commit cf1b625

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

c/cert/src/rules/ARR39-C/DoNotAddOrSubtractAScaledIntegerToAPointer.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import cpp
2020
import codingstandards.c.cert
2121
import codingstandards.cpp.types.Pointers
22-
import semmle.code.cpp.dataflow.TaintTracking
22+
import semmle.code.cpp.dataflow.new.TaintTracking
2323
import ScaledIntegerPointerArithmeticFlow::PathGraph
2424

2525
/**
@@ -61,9 +61,11 @@ class ScaledIntegerExpr extends Expr {
6161
ScaledIntegerExpr() {
6262
not this.getParent*() instanceof ArrayCountOfExpr and
6363
(
64-
this.(SizeofExprOperator).getExprOperand().getType().getSize() > 1
64+
exists(this.getValue()) and
65+
this.getAChild*().(SizeofExprOperator).getExprOperand().getType().getSize() > 1
6566
or
66-
this.(SizeofTypeOperator).getTypeOperand().getSize() > 1
67+
exists(this.getValue()) and
68+
this.getAChild*().(SizeofTypeOperator).getTypeOperand().getSize() > 1
6769
or
6870
this instanceof OffsetOfExpr
6971
)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotAddOrSubtractAScaledIntegerToAPointer.ql:77,56-64)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotAddOrSubtractAScaledIntegerToAPointer.ql:78,22-30)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotAddOrSubtractAScaledIntegerToAPointer.ql:80,20-28)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotAddOrSubtractAScaledIntegerToAPointer.ql:89,45-53)
51
edges
62
| test.c:7:13:7:14 | p1 | test.c:9:9:9:10 | p1 | provenance | |
3+
| test.c:16:19:16:41 | ... - ... | test.c:16:19:16:41 | ... - ... | provenance | |
74
| test.c:16:19:16:41 | ... - ... | test.c:18:26:18:31 | offset | provenance | |
85
| test.c:16:19:16:41 | ... - ... | test.c:29:6:29:11 | offset | provenance | |
6+
| test.c:17:17:17:26 | sizeof(<expr>) | test.c:17:17:17:26 | sizeof(<expr>) | provenance | |
97
| test.c:17:17:17:26 | sizeof(<expr>) | test.c:23:9:23:12 | size | provenance | |
108
| test.c:29:6:29:11 | offset | test.c:7:13:7:14 | p1 | provenance | |
119
nodes
1210
| test.c:7:13:7:14 | p1 | semmle.label | p1 |
1311
| test.c:9:9:9:10 | p1 | semmle.label | p1 |
1412
| test.c:16:19:16:41 | ... - ... | semmle.label | ... - ... |
13+
| test.c:16:19:16:41 | ... - ... | semmle.label | ... - ... |
14+
| test.c:17:17:17:26 | sizeof(<expr>) | semmle.label | sizeof(<expr>) |
1515
| test.c:17:17:17:26 | sizeof(<expr>) | semmle.label | sizeof(<expr>) |
1616
| test.c:18:26:18:31 | offset | semmle.label | offset |
1717
| test.c:23:9:23:12 | size | semmle.label | size |
1818
| test.c:25:9:25:18 | sizeof(<expr>) | semmle.label | sizeof(<expr>) |
19-
| test.c:27:17:27:26 | sizeof(<expr>) | semmle.label | sizeof(<expr>) |
19+
| test.c:27:12:27:26 | ... / ... | semmle.label | ... / ... |
2020
| test.c:29:6:29:11 | offset | semmle.label | offset |
2121
subpaths
2222
#select
2323
| test.c:9:9:9:10 | p1 | test.c:16:19:16:41 | ... - ... | test.c:9:9:9:10 | p1 | Scaled integer used in pointer arithmetic. |
2424
| test.c:18:26:18:31 | offset | test.c:16:19:16:41 | ... - ... | test.c:18:26:18:31 | offset | Scaled integer used in pointer arithmetic. |
2525
| test.c:23:9:23:12 | size | test.c:17:17:17:26 | sizeof(<expr>) | test.c:23:9:23:12 | size | Scaled integer used in pointer arithmetic. |
2626
| test.c:25:9:25:18 | sizeof(<expr>) | test.c:25:9:25:18 | sizeof(<expr>) | test.c:25:9:25:18 | sizeof(<expr>) | Scaled integer used in pointer arithmetic. |
27-
| test.c:27:17:27:26 | sizeof(<expr>) | test.c:27:17:27:26 | sizeof(<expr>) | test.c:27:17:27:26 | sizeof(<expr>) | Scaled integer used in pointer arithmetic. |
27+
| test.c:27:12:27:26 | ... / ... | test.c:27:12:27:26 | ... / ... | test.c:27:12:27:26 | ... / ... | Scaled integer used in pointer arithmetic. |

0 commit comments

Comments
 (0)