Skip to content

Commit fb8bd0e

Browse files
Fix #12489 FN bufferAccessOutOfBounds with overlong strcat() parameter (regression) (danmar#7268)
1 parent b9644e7 commit fb8bd0e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

cfg/std.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,6 +4820,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
48204820
<not-null/>
48214821
<not-uninit/>
48224822
<strz/>
4823+
<minsize type="strlen" arg="2"/>
48234824
</arg>
48244825
<arg nr="2" direction="in">
48254826
<not-null/>

test/cfg/std.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3446,7 +3446,7 @@ void bufferAccessOutOfBounds_strcat(char *dest, const char * const source)
34463446
char buf4[4] = {0};
34473447
const char * const srcstr3 = "123";
34483448
const char * const srcstr4 = "1234";
3449-
// @todo #8599 cppcheck-suppress bufferAccessOutOfBounds
3449+
// cppcheck-suppress bufferAccessOutOfBounds
34503450
(void)strcat(buf4,srcstr4); // off by one issue: strcat is appends \0' at the end
34513451

34523452
// no warning shall be shown for

test/testbufferoverrun.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,6 +3151,20 @@ class TestBufferOverrun : public TestFixture {
31513151
" strcat(n, \"def\");\n"
31523152
"}");
31533153
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: n\n", "", errout_str());
3154+
3155+
check("void f()\n" // #12489
3156+
"{\n"
3157+
" char d[3] = {};\n"
3158+
" strcat(d, \"12345678\");\n"
3159+
"}");
3160+
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: d\n", errout_str());
3161+
3162+
check("void f()\n"
3163+
"{\n"
3164+
" char d[3] = \"ab\"; \n"
3165+
" strcat(d, \"c\");\n"
3166+
"}");
3167+
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: d\n", "", errout_str());
31543168
}
31553169

31563170
void buffer_overrun_7() {

0 commit comments

Comments
 (0)