Skip to content

Commit 2705aeb

Browse files
committed
C++: Restrict CWE-119 semmle tests to have a single main function
1 parent 31f7702 commit 2705aeb

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/OverflowDestination.expected

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
edges
2-
| overflowdestination.cpp:27:9:27:12 | argv | overflowdestination.cpp:30:17:30:20 | (const char *)... |
2+
| main.cpp:7:33:7:36 | argv | main.cpp:7:33:7:36 | argv |
3+
| main.cpp:7:33:7:36 | argv | main.cpp:7:33:7:36 | argv indirection |
4+
| main.cpp:7:33:7:36 | argv | overflowdestination.cpp:23:45:23:48 | argv |
5+
| main.cpp:7:33:7:36 | argv indirection | overflowdestination.cpp:23:45:23:48 | *argv |
6+
| overflowdestination.cpp:23:45:23:48 | *argv | overflowdestination.cpp:30:17:30:20 | (const char *)... |
7+
| overflowdestination.cpp:23:45:23:48 | argv | overflowdestination.cpp:30:17:30:20 | (const char *)... |
38
| overflowdestination.cpp:43:8:43:10 | fgets output argument | overflowdestination.cpp:46:15:46:17 | (const void *)... |
49
| overflowdestination.cpp:50:52:50:54 | *src | overflowdestination.cpp:50:52:50:54 | ReturnIndirection |
510
| overflowdestination.cpp:50:52:50:54 | src | overflowdestination.cpp:53:15:53:17 | (const void *)... |
@@ -17,7 +22,11 @@ edges
1722
| overflowdestination.cpp:76:30:76:32 | src | overflowdestination.cpp:57:52:57:54 | src |
1823
| overflowdestination.cpp:76:30:76:32 | src indirection | overflowdestination.cpp:57:52:57:54 | *src |
1924
nodes
20-
| overflowdestination.cpp:27:9:27:12 | argv | semmle.label | argv |
25+
| main.cpp:7:33:7:36 | argv | semmle.label | argv |
26+
| main.cpp:7:33:7:36 | argv | semmle.label | argv |
27+
| main.cpp:7:33:7:36 | argv indirection | semmle.label | argv indirection |
28+
| overflowdestination.cpp:23:45:23:48 | *argv | semmle.label | *argv |
29+
| overflowdestination.cpp:23:45:23:48 | argv | semmle.label | argv |
2130
| overflowdestination.cpp:30:17:30:20 | (const char *)... | semmle.label | (const char *)... |
2231
| overflowdestination.cpp:43:8:43:10 | fgets output argument | semmle.label | fgets output argument |
2332
| overflowdestination.cpp:46:15:46:17 | (const void *)... | semmle.label | (const void *)... |
@@ -37,7 +46,7 @@ nodes
3746
subpaths
3847
| overflowdestination.cpp:75:30:75:32 | src indirection | overflowdestination.cpp:50:52:50:54 | *src | overflowdestination.cpp:50:52:50:54 | ReturnIndirection | overflowdestination.cpp:75:30:75:32 | overflowdest_test2 output argument |
3948
#select
40-
| overflowdestination.cpp:30:2:30:8 | call to strncpy | overflowdestination.cpp:27:9:27:12 | argv | overflowdestination.cpp:30:17:30:20 | (const char *)... | To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size. |
49+
| overflowdestination.cpp:30:2:30:8 | call to strncpy | main.cpp:7:33:7:36 | argv | overflowdestination.cpp:30:17:30:20 | (const char *)... | To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size. |
4150
| overflowdestination.cpp:46:2:46:7 | call to memcpy | overflowdestination.cpp:43:8:43:10 | fgets output argument | overflowdestination.cpp:46:15:46:17 | (const void *)... | To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size. |
4251
| overflowdestination.cpp:53:2:53:7 | call to memcpy | overflowdestination.cpp:73:8:73:10 | fgets output argument | overflowdestination.cpp:53:15:53:17 | (const void *)... | To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size. |
4352
| overflowdestination.cpp:64:2:64:7 | call to memcpy | overflowdestination.cpp:73:8:73:10 | fgets output argument | overflowdestination.cpp:64:16:64:19 | (const void *)... | To avoid overflow, this operation should be bounded by destination-buffer size, not source-buffer size. |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int overflowdesination_main(int argc, char **argv);
2+
int test_buffer_overrun_main(int argc, char **argv);
3+
int tests_restrict_main(int argc, char **argv);
4+
int tests_main(int argc, char **argv);
5+
6+
int main(int argc, char **argv) {
7+
overflowdesination_main(argc, argv);
8+
test_buffer_overrun_main(argc, argv);
9+
tests_restrict_main(argc, argv);
10+
tests_main(argc, argv);
11+
return 0;
12+
}

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/overflowdestination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inline size_t min(size_t a, size_t b) {
2020
}
2121
}
2222

23-
int main(int argc, char* argv[]) {
23+
int overflowdesination_main(int argc, char* argv[]) {
2424
char param[20];
2525
char *arg1;
2626

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/test_buffer_overrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void test_buffer_overrun_in_while_loop_using_array_indexing()
2929
}
3030
}
3131

32-
int main(int argc, char *argv[])
32+
int test_buffer_overrun_main(int argc, char *argv[])
3333
{
3434
test_buffer_overrun_in_for_loop();
3535
test_buffer_overrun_in_while_loop_using_pointer_arithmetic();

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void test22(bool b, const char* source) {
603603
memcpy(dest, source, n); // GOOD
604604
}
605605

606-
int main(int argc, char *argv[])
606+
int tests_main(int argc, char *argv[])
607607
{
608608
long long arr17[19];
609609

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/tests_restrict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void test1()
1212
memcpy(largebuf, smallbuf, 2); // BAD: source over-read
1313
}
1414

15-
int main(int argc, char *argv[])
15+
int tests_restrict_main(int argc, char *argv[])
1616
{
1717
test1();
1818

0 commit comments

Comments
 (0)