Simplified TestBufferOverrun::readlink test cases (sizeof)
This commit is contained in:
parent
6afdd1b7c0
commit
7871f16e9d
|
@ -3893,51 +3893,45 @@ private:
|
|||
}
|
||||
|
||||
void readlink() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[255];\n"
|
||||
" ssize_t len = readlink(path, buf, sizeof(buf)-1);\n"
|
||||
" ssize_t len = readlink(path, buf, 254);\n"
|
||||
" printf(\"%s\n\", buf);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||
|
||||
// C only: Primitive pointer simplification
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[255];\n"
|
||||
" ssize_t len = readlink(path, &buf[0], sizeof(buf)-1);\n"
|
||||
" ssize_t len = readlink(path, &buf[0], 254);\n"
|
||||
" printf(\"%s\n\", buf);\n"
|
||||
"}\n", true, "test.c");
|
||||
ASSERT_EQUALS("[test.c:4]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||
ASSERT_EQUALS("[test.c:3]: (warning, inconclusive) The buffer 'buf' is not null-terminated after the call to readlink().\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[255];\n"
|
||||
" ssize_t len = readlink(path, buf, sizeof(buf)-1);\n"
|
||||
" ssize_t len = readlink(path, buf, 254);\n"
|
||||
" buf[len] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[10];\n"
|
||||
" ssize_t len = readlink(path, buf, 255);\n"
|
||||
" buf[len] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) readlink() buf size is out of bounds: Supplied size 255 is larger than actual size 10.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) readlink() buf size is out of bounds: Supplied size 255 is larger than actual size 10.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[255];\n"
|
||||
" ssize_t len = readlink(path, buf, sizeof(buf));\n"
|
||||
" ssize_t len = readlink(path, buf, 255);\n"
|
||||
" buf[len] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) readlink() might return the full size of 'buf'. Lower the supplied size by one.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) readlink() might return the full size of 'buf'. Lower the supplied size by one.\n", errout.str());
|
||||
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
check("void f() {\n"
|
||||
" char buf[255];\n"
|
||||
" ssize_t len = readlink(path, buf, sizeof(buf)-1);\n"
|
||||
" ssize_t len = readlink(path, buf, 254);\n"
|
||||
" if (len == -1) {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
|
|
Loading…
Reference in New Issue