Skip to content

Commit 53b86fd

Browse files
authored
Merge pull request #11428 from jketema/default-taint-tests
C++: Add more tests that exercise the default taint barrier implementation
2 parents 8362caa + 4607f59 commit 53b86fd

File tree

2 files changed

+17
-1
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle

2 files changed

+17
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,13 @@ void ptr_diff_case() {
332332
char* admin_begin_pos = strstr(user, "ADMIN");
333333
int offset = admin_begin_pos ? user - admin_begin_pos : 0;
334334
malloc(offset); // GOOD
335-
}
335+
}
336+
337+
void equality_barrier() {
338+
int size1 = atoi(getenv("USER"));
339+
int size2 = atoi(getenv("USER"));
340+
341+
if (size1 == size2) {
342+
int* a = (int*)malloc(size1 * sizeof(int)); // GOOD
343+
}
344+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,12 @@ int main(int argc, char** argv) {
9595
}
9696
}
9797

98+
// GOOD: check the user input first
99+
int maxConnections3 = atoi(argv[1]);
100+
int maxConnections4 = atoi(argv[1]);
101+
if (maxConnections3 == maxConnections4) {
102+
startServer(maxConnections3 * 1000);
103+
}
104+
98105
return 0;
99106
}

0 commit comments

Comments
 (0)