Skip to content

Commit ace7b6b

Browse files
committed
C++: Add cpp/invalid-pointer-deref FP test case
1 parent dd30acf commit ace7b6b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,15 @@ edges
723723
| test.cpp:359:16:359:27 | end_plus_one | test.cpp:358:14:358:26 | Load: * ... |
724724
| test.cpp:359:16:359:27 | end_plus_one | test.cpp:359:14:359:32 | Load: * ... |
725725
| test.cpp:359:16:359:31 | ... + ... | test.cpp:359:14:359:32 | Load: * ... |
726+
| test.cpp:363:14:363:27 | new[] | test.cpp:365:15:365:15 | p |
727+
| test.cpp:365:15:365:15 | p | test.cpp:368:5:368:10 | ... += ... |
728+
| test.cpp:365:15:365:15 | p | test.cpp:368:5:368:10 | ... += ... |
729+
| test.cpp:368:5:368:10 | ... += ... | test.cpp:371:7:371:7 | p |
730+
| test.cpp:368:5:368:10 | ... += ... | test.cpp:371:7:371:7 | p |
731+
| test.cpp:368:5:368:10 | ... += ... | test.cpp:372:16:372:16 | p |
732+
| test.cpp:368:5:368:10 | ... += ... | test.cpp:372:16:372:16 | p |
733+
| test.cpp:371:7:371:7 | p | test.cpp:372:15:372:16 | Load: * ... |
734+
| test.cpp:372:16:372:16 | p | test.cpp:372:15:372:16 | Load: * ... |
726735
nodes
727736
| test.cpp:4:15:4:20 | call to malloc | semmle.label | call to malloc |
728737
| test.cpp:5:15:5:15 | p | semmle.label | p |
@@ -1050,6 +1059,13 @@ nodes
10501059
| test.cpp:359:14:359:32 | Load: * ... | semmle.label | Load: * ... |
10511060
| test.cpp:359:16:359:27 | end_plus_one | semmle.label | end_plus_one |
10521061
| test.cpp:359:16:359:31 | ... + ... | semmle.label | ... + ... |
1062+
| test.cpp:363:14:363:27 | new[] | semmle.label | new[] |
1063+
| test.cpp:365:15:365:15 | p | semmle.label | p |
1064+
| test.cpp:368:5:368:10 | ... += ... | semmle.label | ... += ... |
1065+
| test.cpp:368:5:368:10 | ... += ... | semmle.label | ... += ... |
1066+
| test.cpp:371:7:371:7 | p | semmle.label | p |
1067+
| test.cpp:372:15:372:16 | Load: * ... | semmle.label | Load: * ... |
1068+
| test.cpp:372:16:372:16 | p | semmle.label | p |
10531069
subpaths
10541070
#select
10551071
| 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 |
@@ -1077,3 +1093,4 @@ subpaths
10771093
| test.cpp:350:15:350:19 | Load: * ... | test.cpp:347:14:347:27 | new[] | test.cpp:350:15:350:19 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:347:14:347:27 | new[] | new[] | test.cpp:348:20:348:23 | size | size |
10781094
| test.cpp:358:14:358:26 | Load: * ... | test.cpp:355:14:355:27 | new[] | test.cpp:358:14:358:26 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:355:14:355:27 | new[] | new[] | test.cpp:356:20:356:23 | size | size |
10791095
| test.cpp:359:14:359:32 | Load: * ... | test.cpp:355:14:355:27 | new[] | test.cpp:359:14:359:32 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 2. | test.cpp:355:14:355:27 | new[] | new[] | test.cpp:356:20:356:23 | size | size |
1096+
| test.cpp:372:15:372:16 | Load: * ... | test.cpp:363:14:363:27 | new[] | test.cpp:372:15:372:16 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:363:14:363:27 | new[] | new[] | test.cpp:365:19:365:22 | size | size |

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,17 @@ void test25(unsigned size) {
358358
int val1 = *end_plus_one; // BAD
359359
int val2 = *(end_plus_one + 1); // BAD
360360
}
361+
362+
void test26(unsigned size) {
363+
char *xs = new char[size];
364+
char *p = xs;
365+
char *end = p + size;
366+
367+
if (p + 4 <= end) {
368+
p += 4;
369+
}
370+
371+
if (p < end) {
372+
int val = *p; // GOOD [FALSE POSITIVE]
373+
}
374+
}

0 commit comments

Comments
 (0)