From 65b1a4df197ed61d143e3c9a93fb32206fc4fcb6 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 8 Sep 2011 22:41:18 -0400 Subject: [PATCH] add soem test cases for #3094 (Buffer access out-of-bounds in struct variable) --- test/testbufferoverrun.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 96e8ead5a..b2912952f 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1747,6 +1747,51 @@ private: " strcpy( abc->str, \"abcdef\" );\n" "}\n"); ASSERT_EQUALS("[test.cpp:8]: (error) Buffer access out-of-bounds: abc.str\n", errout.str()); + + check("struct ABC\n" + "{\n" + " char str[5];\n" + "};\n" + "\n" + "static void f()\n" + "{\n" + " struct ABC abc;\n" + " strcpy( abc.str, \"abcdef\" );\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:9]: (error) Buffer access out-of-bounds: abc.str\n", errout.str()); + + check("struct ABC\n" + "{\n" + " char str[5];\n" + "};\n" + "\n" + "static void f(struct ABC &abc)\n" + "{\n" + " strcpy( abc.str, \"abcdef\" );\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Buffer access out-of-bounds: abc.str\n", "", errout.str()); + + check("static void f()\n" + "{\n" + " struct ABC\n" + " {\n" + " char str[5];\n" + " } abc;\n" + " strcpy( abc.str, \"abcdef\" );\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Buffer access out-of-bounds: abc.str\n", "", errout.str()); + + check("static void f()\n" + "{\n" + " struct ABC\n" + " {\n" + " char str[5];\n" + " };\n" + " struct ABC *abc = malloc(sizeof(struct ABC));\n" + " strcpy( abc->str, \"abcdef\" );\n" + " free(abc);\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Buffer access out-of-bounds: abc.str\n", "", errout.str()); }