Skip to content

Commit 11b2a12

Browse files
authored
Merge pull request #10572 from MathiasVP/add-cwe-193-fp
C++: Add FP test for `CWE-193`
2 parents 40a75fd + 1c55bbe commit 11b2a12

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/InvalidPointerDeref.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ edges
677677
| test.cpp:213:6:213:6 | Load | test.cpp:213:5:213:6 | * ... |
678678
| test.cpp:213:6:213:6 | Load | test.cpp:213:5:213:13 | Store: ... = ... |
679679
| test.cpp:213:6:213:6 | Load | test.cpp:213:5:213:13 | Store: ... = ... |
680+
| test.cpp:221:17:221:22 | call to malloc | test.cpp:222:5:222:5 | Load |
681+
| test.cpp:222:5:222:5 | Load | test.cpp:222:5:222:12 | access to array |
682+
| test.cpp:222:5:222:5 | Load | test.cpp:222:5:222:12 | access to array |
683+
| test.cpp:222:5:222:5 | Load | test.cpp:222:5:222:12 | access to array |
684+
| test.cpp:222:5:222:5 | Load | test.cpp:222:5:222:12 | access to array |
685+
| test.cpp:222:5:222:12 | access to array | test.cpp:222:5:222:18 | Store: ... = ... |
686+
| test.cpp:222:5:222:12 | access to array | test.cpp:222:5:222:18 | Store: ... = ... |
680687
#select
681688
| test.cpp:6:14:6:15 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
682689
| test.cpp:8:14:8:21 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:8:14:8:21 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -695,3 +702,4 @@ edges
695702
| test.cpp:171:9:171:14 | Store: ... = ... | test.cpp:143:18:143:23 | call to malloc | test.cpp:171:9:171:14 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:143:18:143:23 | call to malloc | call to malloc | test.cpp:144:29:144:32 | size | size |
696703
| test.cpp:201:5:201:19 | Store: ... = ... | test.cpp:194:23:194:28 | call to malloc | test.cpp:201:5:201:19 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:194:23:194:28 | call to malloc | call to malloc | test.cpp:195:21:195:23 | len | len |
697704
| test.cpp:213:5:213:13 | Store: ... = ... | test.cpp:205:23:205:28 | call to malloc | test.cpp:213:5:213:13 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:205:23:205:28 | call to malloc | call to malloc | test.cpp:206:21:206:23 | len | len |
705+
| test.cpp:222:5:222:18 | Store: ... = ... | test.cpp:221:17:221:22 | call to malloc | test.cpp:222:5:222:18 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:221:17:221:22 | call to malloc | call to malloc | test.cpp:222:7:222:11 | ... - ... | ... - ... |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,13 @@ void test13(unsigned len, unsigned index) {
212212

213213
*q = '\0'; // BAD
214214
}
215+
216+
bool unknown();
217+
218+
void test14(unsigned long n, char *p) {
219+
while (unknown()) {
220+
n++;
221+
p = (char *)malloc(n);
222+
p[n - 1] = 'a'; // GOOD [FALSE POSITIVE]
223+
}
224+
}

0 commit comments

Comments
 (0)