testbufferoverrun: refactor TODO test cases. Use TODO_ASSERT_EQUALS.
This commit is contained in:
parent
a2ff7752b4
commit
a07ea7e9e9
|
@ -184,7 +184,7 @@ private:
|
|||
TEST_CASE(buffer_overrun_errorpath);
|
||||
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
|
||||
TEST_CASE(buffer_overrun_function_array_argument);
|
||||
// TODO alloca TEST_CASE(possible_buffer_overrun_1); // #3035
|
||||
TEST_CASE(possible_buffer_overrun_1); // #3035
|
||||
TEST_CASE(buffer_overrun_readSizeFromCfg);
|
||||
|
||||
TEST_CASE(valueflow_string); // using ValueFlow string values in checking
|
||||
|
@ -207,10 +207,10 @@ private:
|
|||
|
||||
TEST_CASE(assign1);
|
||||
|
||||
// TODO new TEST_CASE(alloc_new); // Buffer allocated with new
|
||||
TEST_CASE(alloc_new); // Buffer allocated with new
|
||||
TEST_CASE(alloc_malloc); // Buffer allocated with malloc
|
||||
TEST_CASE(alloc_string); // statically allocated buffer
|
||||
// TODO TEST_CASE(alloc_alloca); // Buffer allocated with alloca
|
||||
TEST_CASE(alloc_alloca); // Buffer allocated with alloca
|
||||
|
||||
// TODO TEST_CASE(countSprintfLength);
|
||||
TEST_CASE(minsize_argvalue);
|
||||
|
@ -233,8 +233,8 @@ private:
|
|||
TEST_CASE(crash6); // Ticket #9024 - crash
|
||||
TEST_CASE(crash7); // Ticket #9073 - crash
|
||||
|
||||
// TODO TEST_CASE(insecureCmdLineArgs);
|
||||
// TODO TEST_CASE(checkBufferAllocatedWithStrlen);
|
||||
TEST_CASE(insecureCmdLineArgs);
|
||||
TEST_CASE(checkBufferAllocatedWithStrlen);
|
||||
|
||||
TEST_CASE(scope); // handling different scopes
|
||||
|
||||
|
@ -243,9 +243,9 @@ private:
|
|||
// Access array and then check if the used index is within bounds
|
||||
TEST_CASE(arrayIndexThenCheck);
|
||||
|
||||
// TODO TEST_CASE(bufferNotZeroTerminated);
|
||||
TEST_CASE(bufferNotZeroTerminated);
|
||||
|
||||
// TODO TEST_CASE(negativeMemoryAllocationSizeError) // #389
|
||||
TEST_CASE(negativeMemoryAllocationSizeError); // #389
|
||||
TEST_CASE(negativeArraySize);
|
||||
|
||||
TEST_CASE(pointerAddition1);
|
||||
|
@ -2809,7 +2809,7 @@ private:
|
|||
" src[99] = '\\0';\n"
|
||||
" strcat(data, src);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" char * data = (char *)alloca(100);\n"
|
||||
|
@ -2824,7 +2824,7 @@ private:
|
|||
" char * data = (char *)alloca(50);\n"
|
||||
" strcat(data, src);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than sizeof(data)-strlen(data).\n", "", errout.str());
|
||||
|
||||
check("void foo(char src[100]) {\n"
|
||||
" char * data = (char *)alloca(100);\n"
|
||||
|
@ -2839,7 +2839,7 @@ private:
|
|||
" src[99] = '\\0';\n"
|
||||
" strcpy(data, src);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" char * data = (char *)alloca(100);\n"
|
||||
|
@ -2854,7 +2854,7 @@ private:
|
|||
" char * data = (char *)alloca(50);\n"
|
||||
" strcpy(data, src);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Possible buffer overflow if strlen(src) is larger than or equal to sizeof(data).\n", "", errout.str());
|
||||
|
||||
check("void foo(char src[100]) {\n"
|
||||
" char * data = (char *)alloca(100);\n"
|
||||
|
@ -3096,7 +3096,7 @@ private:
|
|||
" char *s; s = new char[10];\n"
|
||||
" s[10] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
|
||||
// ticket #1670 - false negative when using return
|
||||
check("char f()\n"
|
||||
|
@ -3104,7 +3104,7 @@ private:
|
|||
" int *s; s = new int[10];\n"
|
||||
" return s[10];\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
|
||||
check("struct Fred { char c[10]; };\n"
|
||||
"char f()\n"
|
||||
|
@ -3137,7 +3137,7 @@ private:
|
|||
" buf[9] = 0;\n"
|
||||
" delete [] buf;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array 'buf[9]' accessed at index 9, which is out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
@ -3145,7 +3145,7 @@ private:
|
|||
" char *s; s = new char[Size];\n"
|
||||
" s[Size] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
@ -3153,7 +3153,7 @@ private:
|
|||
" E *e; e = new E[10];\n"
|
||||
" e[10] = ZERO;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'e[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array 'e[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
}
|
||||
|
||||
// data is allocated with malloc
|
||||
|
@ -3276,7 +3276,7 @@ private:
|
|||
" char *s = (char *)alloca(10);\n"
|
||||
" s[10] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", "", errout.str());
|
||||
}
|
||||
/*
|
||||
void countSprintfLength() const {
|
||||
|
@ -3887,7 +3887,7 @@ private:
|
|||
" }\n"
|
||||
" return 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char *argv[])\n"
|
||||
"{\n"
|
||||
|
@ -3900,112 +3900,112 @@ private:
|
|||
" }\n"
|
||||
" return 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(const int argc, char* argv[])\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, const char* argv[])\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(const int argc, const char* argv[])\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char* argv[])\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, const char *const *const argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(const int argc, const char *const *const argv, const char *const *const envp)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(const int argc, const char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, const char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(const int argc, char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **options)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, options[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **options)\n"
|
||||
"{\n"
|
||||
" char prog[10] = {'\\0'};\n"
|
||||
" strcat(prog, options[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **options)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog, *options);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **options)\n"
|
||||
"{\n"
|
||||
" char prog[10];\n"
|
||||
" strcpy(prog+3, *options);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
check("int main(int argc, char **argv, char **envp)\n"
|
||||
"{\n"
|
||||
|
@ -4037,8 +4037,8 @@ private:
|
|||
" strcpy(prog, argv[0]);\n"
|
||||
" strcpy(prog, argv[0]);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\n"
|
||||
"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer overrun possible for long command line arguments.\n"
|
||||
"[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", "", errout.str());
|
||||
|
||||
// #7964
|
||||
check("int main(int argc, char *argv[]) {\n"
|
||||
|
@ -4056,7 +4056,7 @@ private:
|
|||
" char *b = new char[strlen(a)];\n"
|
||||
" strcpy(b, a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void f(char *a) {\n"
|
||||
" char *b = new char[strlen(a) + 1];\n"
|
||||
|
@ -4082,7 +4082,7 @@ private:
|
|||
" char *b = (char *)malloc(strlen(a));\n"
|
||||
" strcpy(b, a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void f(char *a) {\n"
|
||||
" char *b = (char *)malloc(strlen(a));\n"
|
||||
|
@ -4090,7 +4090,7 @@ private:
|
|||
" strcpy(b, a);\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void f(char *a) {\n"
|
||||
" char *b = (char *)malloc(strlen(a) + 1);\n"
|
||||
|
@ -4102,7 +4102,7 @@ private:
|
|||
" char *b = (char *)realloc(c, strlen(a));\n"
|
||||
" strcpy(b, a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
|
||||
|
||||
check("void f(char *a, char *c) {\n"
|
||||
" char *b = (char *)realloc(c, strlen(a) + 1);\n"
|
||||
|
@ -4114,7 +4114,7 @@ private:
|
|||
" char *b = (char *)malloc(strlen(a));\n"
|
||||
" strcpy(b, a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", "", errout.str());
|
||||
}
|
||||
|
||||
void scope() {
|
||||
|
@ -4225,19 +4225,19 @@ private:
|
|||
" char c[6];\n"
|
||||
" strncpy(c,\"hello!\",6);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to strncpy().\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to strncpy().\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char c[6];\n"
|
||||
" memcpy(c,\"hello!\",6);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memcpy().\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memcpy().\n", "", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char c[6];\n"
|
||||
" memmove(c,\"hello!\",6);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memmove().\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' may not be null-terminated after the call to memmove().\n", "", errout.str());
|
||||
}
|
||||
|
||||
void negativeMemoryAllocationSizeError() { // #389
|
||||
|
@ -4247,7 +4247,7 @@ private:
|
|||
" a = (int *)malloc( -10 );\n"
|
||||
" free(a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
@ -4255,14 +4255,14 @@ private:
|
|||
" a = (int *)malloc( -10);\n"
|
||||
" free(a);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" int *a;\n"
|
||||
" a = (int *)alloca( -10 );\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", "", errout.str());
|
||||
}
|
||||
|
||||
void negativeArraySize() {
|
||||
|
|
Loading…
Reference in New Issue