fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

test_strncat_static_write.c (393B)


      1 #include "common.h"
      2 
      3 #include <string.h>
      4 
      5 int main(int argc, char** argv) {
      6   char buffer[8] = {0};
      7   strncat(buffer, "12345", 5);
      8   puts(buffer);
      9 
     10   /* n=4 is less than buffer size (8), but buffer already has 5 chars,
     11    * so appending 4 more + NUL = 10 bytes total, overflowing the buffer.
     12    */
     13   CHK_FAIL_START
     14   strncat(buffer, "ABCD", 4);
     15   CHK_FAIL_END
     16 
     17   puts(buffer);
     18   return ret;
     19 }