From 01af70cc88be41341dccfd330b808abfcc5c5503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Oct 2009 19:36:48 +0200 Subject: [PATCH] Fixed #823 (Buffer overrun with memcpy) --- src/checkbufferoverrun.cpp | 2 +- test/testbufferoverrun.cpp | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index 8c4d92cdd..70ed7c5a1 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -88,7 +88,7 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok) severity = Severity::error; } - reportError(tok, severity, "bufferOverrun", "Buffer overrun"); + reportError(tok, severity, "bufferAccessOutOfBounds", "Buffer access out-of-bounds"); } void CheckBufferOverrun::dangerousStdCin(const Token *tok) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 4839b61e7..8e742b938 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -270,7 +270,7 @@ private: " for (i = 0; i < 100; i++)\n" " sum += val[i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str()); } { @@ -281,7 +281,7 @@ private: " for (i = 1; i < 100; i++)\n" " sum += val[i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str()); } @@ -293,7 +293,7 @@ private: " for (i = a; i < 100; i++)\n" " sum += val[i];\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str()); } } @@ -630,7 +630,7 @@ private: " char str[3];\n" " strcpy(str, \"abc\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } @@ -645,7 +645,7 @@ private: "{\n" " strcpy( abc->str, \"abcdef\" );\n" "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Buffer access out-of-bounds\n", errout.str()); } @@ -659,7 +659,7 @@ private: " for (i = 0; i <= 10; ++i)\n" " a[i] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:7]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:7]: (error) Buffer access out-of-bounds\n", errout.str()); } @@ -671,7 +671,7 @@ private: " for (int i = 0; i < 8; ++i)\n" " p[i] = 0;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Buffer access out-of-bounds\n", errout.str()); // No false positive check("void foo(int x, int y)\n" @@ -692,7 +692,7 @@ private: " char s[3];\n" " f1(s,3);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (possible error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (possible error) Buffer access out-of-bounds\n", errout.str()); TODO_ASSERT_EQUALS("", errout.str()); check("void f1(char *s,int size)\n" @@ -726,14 +726,14 @@ private: " strcat(n, \"abc\");\n" " strcat(n, \"def\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (error) Buffer access out-of-bounds\n", errout.str()); check("void f()\n" "{\n" " char n[5];\n" " strcat(strcat(n, \"abc\"), \"def\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } void buffer_overrun_7() @@ -847,7 +847,7 @@ private: " char str[3];\n" " sprintf(str, \"%s\", \"abc\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); check("void f()\n" "{\n" @@ -855,7 +855,7 @@ private: " sprintf(c, \"%s\", \"/usr/LongLongLongLongUserName/bin/LongLongApplicationName\");\n" " delete [] c;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } void sprintf2() @@ -865,7 +865,7 @@ private: " char str[5];\n" " sprintf(str, \"%d: %s\", getnumber(), \"abcde\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } void sprintf3() @@ -875,7 +875,7 @@ private: " char str[3];\n" " sprintf(str, \"test\");\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); check("void f()\n" "{\n" @@ -914,7 +914,7 @@ private: " char buf[3];\n" " sprintf(buf, \"%s\", condition ? \"11\" : \"222\");\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } void snprintf1() @@ -1159,7 +1159,7 @@ private: " strcpy(a,\"hello\");\n" " strncpy(c,a,sizeof(c)+1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str()); check("void f()\n" "{\n" @@ -1173,7 +1173,7 @@ private: " char c[6];\n" " strncpy(c,\"hello!\",sizeof(c)+1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Buffer overrun\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str()); } };