fortify-headers

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

test_wcsncat_n_one.c (379B)


      1 #include "common.h"
      2 
      3 #include <wchar.h>
      4 
      5 int main(int argc, char** argv) {
      6   wchar_t buffer[8] = {0};
      7   wcsncat(buffer, L"1234567", 7);
      8   printf("%ls\n", buffer);
      9 
     10   /* n=1, buffer has 7 wchars.
     11    * 7+1+1 = 9 > 8 → overflow. Even n=1 can overflow a nearly-full buffer. */
     12   CHK_FAIL_START
     13   wcsncat(buffer, L"X", 1);
     14   CHK_FAIL_END
     15 
     16   printf("%ls\n", buffer);
     17   return ret;
     18 }