Skip to content

Commit 263e51f

Browse files
committed
C++: Clean up the test.
1 parent 4355f8d commit 263e51f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/TaintedAllocationSize/TaintedAllocationSize.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
| test.cpp:49:17:49:30 | new[] | This allocation size is derived from $@ and might overflow | test.cpp:39:21:39:24 | argv | user input (argv) |
77
| test.cpp:52:21:52:27 | call to realloc | This allocation size is derived from $@ and might overflow | test.cpp:39:21:39:24 | argv | user input (argv) |
88
| test.cpp:52:35:52:60 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:39:21:39:24 | argv | user input (argv) |
9-
| test.cpp:127:17:127:22 | call to malloc | This allocation size is derived from $@ and might overflow | test.cpp:123:25:123:30 | call to getenv | user input (getenv) |
9+
| test.cpp:127:17:127:22 | call to malloc | This allocation size is derived from $@ and might overflow | test.cpp:123:18:123:23 | call to getenv | user input (getenv) |
10+
| test.cpp:127:24:127:41 | ... * ... | This allocation size is derived from $@ and might overflow | test.cpp:123:18:123:23 | call to getenv | user input (getenv) |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/TaintedAllocationSize/test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ int main(int argc, char **argv) {
3939
int tainted = atoi(argv[1]);
4040

4141
MyStruct *arr1 = (MyStruct *)malloc(sizeof(MyStruct)); // GOOD
42-
MyStruct *arr2 = (MyStruct *)malloc(tainted); // BAD
42+
MyStruct *arr2 = (MyStruct *)malloc(tainted); // DUBIOUS (not multiplied by anything)
4343
MyStruct *arr3 = (MyStruct *)malloc(tainted * sizeof(MyStruct)); // BAD
4444
MyStruct *arr4 = (MyStruct *)malloc(getTainted() * sizeof(MyStruct)); // BAD [NOT DETECTED]
45-
MyStruct *arr5 = (MyStruct *)malloc(sizeof(MyStruct) + tainted); // BAD [NOT DETECTED]
45+
MyStruct *arr5 = (MyStruct *)malloc(sizeof(MyStruct) + tainted); // DUBIOUS (not multiplied by anything)
4646

4747
int size = tainted * 8;
4848
char *chars1 = (char *)malloc(size); // BAD
@@ -52,7 +52,7 @@ int main(int argc, char **argv) {
5252
arr1 = (MyStruct *)realloc(arr1, sizeof(MyStruct) * tainted); // BAD
5353

5454
size = 8;
55-
chars3 = new char[size]; // GOOD [FALSE POSITIVE]
55+
chars3 = new char[size]; // GOOD
5656

5757
return 0;
5858
}
@@ -120,9 +120,9 @@ int bounded(int x, int limit) {
120120
}
121121

122122
void open_file_bounded () {
123-
int size = size = atoi(getenv("USER"));
123+
int size = atoi(getenv("USER"));
124124
int bounded_size = bounded(size, MAX_SIZE);
125125

126-
int* a = (int*)malloc(bounded_size); // GOOD
127-
int* b = (int*)malloc(size); // BAD
128-
}
126+
int* a = (int*)malloc(bounded_size * sizeof(int)); // GOOD
127+
int* b = (int*)malloc(size * sizeof(int)); // BAD
128+
}

0 commit comments

Comments
 (0)