fortify-headers

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

test_stpncpy_overwrite_under.c (389B)


      1 #include "common.h"
      2 
      3 #include <string.h>
      4 
      5 int main(int argc, char** argv) {
      6   char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'};
      7   puts(buffer);
      8 
      9   stpncpy(buffer+5, buffer, 2);
     10   puts(buffer);
     11 
     12   char buffer2[] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'};
     13 #if 0
     14   CHK_FAIL_START
     15   stpncpy(buffer2-1, buffer2, 5);
     16   CHK_FAIL_END
     17 #endif
     18 
     19   puts(buffer2);
     20   return ret;
     21 }