fortify-headers

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

test_strncpy_overwrite_over.c (439B)


      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   strncpy(buffer, buffer+4, 1);
     10   puts(buffer);
     11 
     12   strncpy(buffer+6, buffer, 1);
     13   puts(buffer);
     14 
     15   char buffer2[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'};
     16 #if 0
     17   CHK_FAIL_START
     18   strncpy(buffer2+1, buffer2, 5);
     19   CHK_FAIL_END
     20 #endif
     21 
     22   puts(buffer2);
     23   return ret;
     24 }