Skip to content

Commit c3fdc83

Browse files
committed
C++: Also add an out barrier on all sinks.
1 parent ebc1d5f commit c3fdc83

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-193/ConstantSizeArrayOffByOne.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ module PointerArithmeticToDerefConfig implements DataFlow::ConfigSig {
9797

9898
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
9999

100+
predicate isBarrierOut(DataFlow::Node node) { isSink(node) }
101+
100102
predicate isSink(DataFlow::Node sink) { isInvalidPointerDerefSink1(sink, _, _) }
101103
}
102104

@@ -134,6 +136,8 @@ module FieldAddressToDerefConfig implements DataFlow::StateConfigSig {
134136

135137
predicate isBarrierIn(DataFlow::Node node) { isSource(node, _) }
136138

139+
predicate isBarrierOut(DataFlow::Node node) { isSink(node, _) }
140+
137141
predicate isAdditionalFlowStep(
138142
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
139143
) {

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/constant-size/ConstantSizeArrayOffByOne.expected

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ edges
66
| test.cpp:50:10:50:12 | buf | test.cpp:50:5:50:24 | access to array |
77
| test.cpp:57:14:57:16 | buf | test.cpp:57:9:57:19 | access to array |
88
| test.cpp:61:14:61:16 | buf | test.cpp:61:9:61:19 | access to array |
9-
| test.cpp:66:32:66:32 | p | test.cpp:66:32:66:32 | p |
10-
| test.cpp:66:32:66:32 | p | test.cpp:67:5:67:6 | * ... |
11-
| test.cpp:66:32:66:32 | p | test.cpp:67:6:67:6 | p |
129
| test.cpp:70:33:70:33 | p | test.cpp:72:5:72:15 | access to array |
1310
| test.cpp:77:26:77:44 | & ... | test.cpp:66:32:66:32 | p |
14-
| test.cpp:77:26:77:44 | & ... | test.cpp:66:32:66:32 | p |
1511
| test.cpp:77:32:77:34 | buf | test.cpp:77:26:77:44 | & ... |
1612
| test.cpp:79:27:79:34 | buf | test.cpp:70:33:70:33 | p |
1713
| test.cpp:79:32:79:34 | buf | test.cpp:79:27:79:34 | buf |
@@ -31,10 +27,6 @@ nodes
3127
| test.cpp:61:9:61:19 | access to array | semmle.label | access to array |
3228
| test.cpp:61:14:61:16 | buf | semmle.label | buf |
3329
| test.cpp:66:32:66:32 | p | semmle.label | p |
34-
| test.cpp:66:32:66:32 | p | semmle.label | p |
35-
| test.cpp:66:32:66:32 | p | semmle.label | p |
36-
| test.cpp:67:5:67:6 | * ... | semmle.label | * ... |
37-
| test.cpp:67:6:67:6 | p | semmle.label | p |
3830
| test.cpp:70:33:70:33 | p | semmle.label | p |
3931
| test.cpp:72:5:72:15 | access to array | semmle.label | access to array |
4032
| test.cpp:77:26:77:44 | & ... | semmle.label | & ... |
@@ -52,6 +44,3 @@ subpaths
5244
| test.cpp:61:9:61:19 | PointerAdd: access to array | test.cpp:61:14:61:16 | buf | test.cpp:61:9:61:19 | access to array | This pointer arithmetic may have an off-by-2 error allowing it to overrun $@ at this $@. | test.cpp:19:9:19:11 | buf | buf | test.cpp:61:9:61:23 | Store: ... = ... | write |
5345
| test.cpp:72:5:72:15 | PointerAdd: access to array | test.cpp:79:32:79:34 | buf | test.cpp:72:5:72:15 | access to array | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:72:5:72:19 | Store: ... = ... | write |
5446
| test.cpp:77:27:77:44 | PointerAdd: access to array | test.cpp:77:32:77:34 | buf | test.cpp:66:32:66:32 | p | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
55-
| test.cpp:77:27:77:44 | PointerAdd: access to array | test.cpp:77:32:77:34 | buf | test.cpp:66:32:66:32 | p | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
56-
| test.cpp:77:27:77:44 | PointerAdd: access to array | test.cpp:77:32:77:34 | buf | test.cpp:67:5:67:6 | * ... | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
57-
| test.cpp:77:27:77:44 | PointerAdd: access to array | test.cpp:77:32:77:34 | buf | test.cpp:67:6:67:6 | p | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |

0 commit comments

Comments
 (0)