Skip to content

Commit 01fc743

Browse files
committed
C++: Add more tests.
1 parent bf84f3a commit 01fc743

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-843/TypeConfusion.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ edges
88
| test.cpp:153:9:153:15 | new | test.cpp:159:14:159:33 | a | provenance | |
99
| test.cpp:168:9:168:15 | new | test.cpp:171:14:171:33 | a | provenance | |
1010
| test.cpp:187:15:187:24 | new | test.cpp:189:25:189:45 | u64 | provenance | |
11+
| test.cpp:217:13:217:18 | new | test.cpp:218:30:218:65 | p | provenance | |
12+
| test.cpp:226:13:226:18 | new | test.cpp:227:29:227:63 | p | provenance | |
1113
nodes
1214
| test.cpp:27:13:27:18 | new | semmle.label | new |
1315
| test.cpp:28:25:28:55 | p | semmle.label | p |
@@ -27,6 +29,10 @@ nodes
2729
| test.cpp:171:14:171:33 | a | semmle.label | a |
2830
| test.cpp:187:15:187:24 | new | semmle.label | new |
2931
| test.cpp:189:25:189:45 | u64 | semmle.label | u64 |
32+
| test.cpp:217:13:217:18 | new | semmle.label | new |
33+
| test.cpp:218:30:218:65 | p | semmle.label | p |
34+
| test.cpp:226:13:226:18 | new | semmle.label | new |
35+
| test.cpp:227:29:227:63 | p | semmle.label | p |
3036
subpaths
3137
#select
3238
| test.cpp:28:25:28:55 | p | test.cpp:27:13:27:18 | new | test.cpp:28:25:28:55 | p | Conversion from $@ to $@ is invalid. | test.cpp:1:8:1:9 | S1 | S1 | test.cpp:11:8:11:21 | Not_S1_wrapper | Not_S1_wrapper |
@@ -36,3 +42,5 @@ subpaths
3642
| test.cpp:145:28:145:68 | s1_2 | test.cpp:143:14:143:19 | new | test.cpp:145:28:145:68 | s1_2 | Conversion from $@ to $@ is invalid. | test.cpp:1:8:1:9 | S1 | S1 | test.cpp:131:8:131:23 | HasSomeBitFields | HasSomeBitFields |
3743
| test.cpp:159:14:159:33 | a | test.cpp:153:9:153:15 | new | test.cpp:159:14:159:33 | a | Conversion from $@ to $@ is invalid. | test.cpp:60:8:60:10 | Dog | Dog | test.cpp:55:8:55:10 | Cat | Cat |
3844
| test.cpp:189:25:189:45 | u64 | test.cpp:187:15:187:24 | new | test.cpp:189:25:189:45 | u64 | Conversion from $@ to $@ is invalid. | test.cpp:175:8:175:13 | UInt64 | UInt64 | test.cpp:184:8:184:22 | UInt8_with_more | UInt8_with_more |
45+
| test.cpp:218:30:218:65 | p | test.cpp:217:13:217:18 | new | test.cpp:218:30:218:65 | p | Conversion from $@ to $@ is invalid. | test.cpp:1:8:1:9 | S1 | S1 | test.cpp:212:8:212:26 | UnrelatedStructSize | UnrelatedStructSize |
46+
| test.cpp:227:29:227:63 | p | test.cpp:226:13:226:18 | new | test.cpp:227:29:227:63 | p | Conversion from $@ to $@ is invalid. | test.cpp:1:8:1:9 | S1 | S1 | test.cpp:221:8:221:25 | TooLargeBufferSize | TooLargeBufferSize |

cpp/ql/test/query-tests/Security/CWE/CWE-843/test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,22 @@ void test16() {
209209
MyUnion* mu = (MyUnion*)si; // BAD [NOT DETECTED]
210210
}
211211

212+
struct UnrelatedStructSize {
213+
unsigned char buffer[1024];
214+
};
215+
216+
void test17() {
217+
void* p = new S1;
218+
UnrelatedStructSize* uss = static_cast<UnrelatedStructSize*>(p); // BAD
219+
}
220+
221+
struct TooLargeBufferSize {
222+
unsigned char buffer[sizeof(S1) + 1];
223+
};
224+
225+
void test18() {
226+
void* p = new S1;
227+
TooLargeBufferSize* uss = static_cast<TooLargeBufferSize*>(p); // BAD
228+
}
229+
212230
// semmle-extractor-options: --gcc -std=c++11

0 commit comments

Comments
 (0)