Menu

strncpy bufferoverrun test

versat
2017-12-08
2017-12-11
  • versat

    versat - 2017-12-08

    Hi,
    after reading the ticket https://trac.cppcheck.net/ticket/8293
    i wanted to create a test to verify the detection of bufferoverruns with strncpy().
    So i added this code:

        void strncpy1() {
            check("void f() {\n"
                  "    char str[5];\n"
                  "    strncpy(str, \"a\", 10);\n"
                  "}");
            ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: str\n", errout.str());
        }
    

    I realized that the class TestBufferOverrun does not use std.cfg, but the test needs it.
    I'm not sure if it is ok to add std.cfg to the settings0 (i guess not), use another settings1 variable or place the test somewhere else.
    What would you say?

     
  • Daniel Marjamäki

    the testrunner should not depend on files.

    If you want to test that std.cfg is configured correctly then edit test/cfg/std.c.

    If you want to test that the checker treats the library info correctly then the test should be in the testrunner. There is a similar test that has a "mystrncpy" function.. you can look at how that is implemented.

     
  • versat

    versat - 2017-12-11

    I see, i want to add checks to verify that the strncpy tests work correctly, i.e. if the library is configured correctly and errors (bufferoverflows) are detected by Cppcheck. So the tests should be implemented in std.c.

    Thanks for the hint to the mystrncpy tests in testrunner.
    They seem to be missing something too when looking at the tickets https://trac.cppcheck.net/ticket/8294 and https://trac.cppcheck.net/ticket/8293.

     

    Last edit: versat 2017-12-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.