Skip to content

Commit cf6bdc2

Browse files
authored
Merge pull request github#13623 from MathiasVP/speed-up-overrun-write
C++: Speed up `cpp/overrun-write`
2 parents f8b1dc9 + 9791640 commit cf6bdc2

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

cpp/ql/src/Security/CWE/CWE-119/OverrunWriteProductFlow.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ module ValidState {
120120

121121
predicate isBarrier(DataFlow::Node node, FlowState state) { none() }
122122

123+
predicate isBarrierOut(DataFlow::Node node) {
124+
node = any(DataFlow::SsaPhiNode phi).getAnInput(true)
125+
}
126+
123127
predicate isAdditionalFlowStep(
124128
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
125129
) {
@@ -233,7 +237,8 @@ module StringSizeConfig implements ProductFlow::StateConfigSig {
233237
// we use `state2` to remember that there was an offset (in this case an offset of `1`) added
234238
// to the size of the allocation. This state is then checked in `isSinkPair`.
235239
exists(state1) and
236-
hasSize(bufSource.asConvertedExpr(), sizeSource, state2)
240+
hasSize(bufSource.asConvertedExpr(), sizeSource, state2) and
241+
validState(sizeSource, state2)
237242
}
238243

239244
predicate isSinkPair(

cpp/ql/test/query-tests/Security/CWE/CWE-119/SAMATE/OverrunWriteProductFlow.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ edges
7575
| test.cpp:214:24:214:24 | p | test.cpp:216:10:216:10 | p |
7676
| test.cpp:220:43:220:48 | call to malloc | test.cpp:222:15:222:20 | buffer |
7777
| test.cpp:222:15:222:20 | buffer | test.cpp:214:24:214:24 | p |
78-
| test.cpp:228:43:228:48 | call to malloc | test.cpp:232:10:232:15 | buffer |
7978
| test.cpp:235:40:235:45 | buffer | test.cpp:236:5:236:26 | ... = ... |
8079
| test.cpp:236:5:236:26 | ... = ... | test.cpp:236:12:236:17 | p_str indirection [post update] [string] |
8180
| test.cpp:241:27:241:32 | call to malloc | test.cpp:242:22:242:27 | buffer |
@@ -86,7 +85,6 @@ edges
8685
| test.cpp:243:12:243:14 | str indirection [string] | test.cpp:243:16:243:21 | string indirection |
8786
| test.cpp:243:16:243:21 | string indirection | test.cpp:243:12:243:21 | string |
8887
| test.cpp:249:20:249:27 | call to my_alloc | test.cpp:250:12:250:12 | p |
89-
| test.cpp:256:17:256:22 | call to malloc | test.cpp:257:12:257:12 | p |
9088
| test.cpp:262:22:262:27 | call to malloc | test.cpp:266:12:266:12 | p |
9189
| test.cpp:264:20:264:25 | call to malloc | test.cpp:266:12:266:12 | p |
9290
nodes
@@ -155,8 +153,6 @@ nodes
155153
| test.cpp:216:10:216:10 | p | semmle.label | p |
156154
| test.cpp:220:43:220:48 | call to malloc | semmle.label | call to malloc |
157155
| test.cpp:222:15:222:20 | buffer | semmle.label | buffer |
158-
| test.cpp:228:43:228:48 | call to malloc | semmle.label | call to malloc |
159-
| test.cpp:232:10:232:15 | buffer | semmle.label | buffer |
160156
| test.cpp:235:40:235:45 | buffer | semmle.label | buffer |
161157
| test.cpp:236:5:236:26 | ... = ... | semmle.label | ... = ... |
162158
| test.cpp:236:12:236:17 | p_str indirection [post update] [string] | semmle.label | p_str indirection [post update] [string] |
@@ -168,8 +164,6 @@ nodes
168164
| test.cpp:243:16:243:21 | string indirection | semmle.label | string indirection |
169165
| test.cpp:249:20:249:27 | call to my_alloc | semmle.label | call to my_alloc |
170166
| test.cpp:250:12:250:12 | p | semmle.label | p |
171-
| test.cpp:256:17:256:22 | call to malloc | semmle.label | call to malloc |
172-
| test.cpp:257:12:257:12 | p | semmle.label | p |
173167
| test.cpp:262:22:262:27 | call to malloc | semmle.label | call to malloc |
174168
| test.cpp:264:20:264:25 | call to malloc | semmle.label | call to malloc |
175169
| test.cpp:266:12:266:12 | p | semmle.label | p |

0 commit comments

Comments
 (0)