mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C++: Add another test case.
This commit is contained in:
@@ -402,13 +402,36 @@ void test_vector_output_iterator(int b) {
|
||||
|
||||
void *memcpy(void *s1, const void *s2, size_t n);
|
||||
|
||||
namespace ns_string
|
||||
{
|
||||
std::string source();
|
||||
}
|
||||
|
||||
void sink(std::vector<char> &);
|
||||
void sink(std::string &);
|
||||
|
||||
void test_vector_memcpy()
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
int s = source();
|
||||
int i = 0;
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
int s = source();
|
||||
int i = 0;
|
||||
|
||||
sink(v);
|
||||
memcpy(&v[i], &s, sizeof(int));
|
||||
sink(v); // tainted [NOT DETECTED by IR]
|
||||
sink(v);
|
||||
memcpy(&v[i], &s, sizeof(int));
|
||||
sink(v); // tainted [NOT DETECTED by IR]
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<char> cs(100);
|
||||
std::string src = ns_string::source();
|
||||
const size_t offs = 10;
|
||||
const size_t len = src.length();
|
||||
|
||||
sink(src); // tainted
|
||||
sink(cs);
|
||||
memcpy(&cs[offs + 1], src.c_str(), len);
|
||||
sink(src); // tainted
|
||||
sink(cs); // tainted [NOT DETECTED by IR]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user