Loading compiler-rt/lib/msan/msan_interceptors.cc +1 −0 Original line number Diff line number Diff line Loading @@ -260,6 +260,7 @@ INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) { // NOLINT copy_size++; // trailing \0 char *res = REAL(strncpy)(dest, src, n); // NOLINT CopyPoison(dest, src, copy_size, &stack); __msan_unpoison(dest + copy_size, n - copy_size); return res; } Loading compiler-rt/lib/msan/tests/msan_test.cc +6 −4 Original line number Diff line number Diff line Loading @@ -1483,14 +1483,16 @@ TEST(MemorySanitizer, strcpy) { // NOLINT TEST(MemorySanitizer, strncpy) { // NOLINT char* x = new char[3]; char* y = new char[3]; char* y = new char[5]; x[0] = 'a'; x[1] = *GetPoisoned<char>(1, 1); x[2] = 0; strncpy(y, x, 2); // NOLINT x[2] = '\0'; strncpy(y, x, 4); // NOLINT EXPECT_NOT_POISONED(y[0]); EXPECT_POISONED(y[1]); EXPECT_POISONED(y[2]); EXPECT_NOT_POISONED(y[2]); EXPECT_NOT_POISONED(y[3]); EXPECT_POISONED(y[4]); } TEST(MemorySanitizer, stpcpy) { // NOLINT Loading Loading
compiler-rt/lib/msan/msan_interceptors.cc +1 −0 Original line number Diff line number Diff line Loading @@ -260,6 +260,7 @@ INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) { // NOLINT copy_size++; // trailing \0 char *res = REAL(strncpy)(dest, src, n); // NOLINT CopyPoison(dest, src, copy_size, &stack); __msan_unpoison(dest + copy_size, n - copy_size); return res; } Loading
compiler-rt/lib/msan/tests/msan_test.cc +6 −4 Original line number Diff line number Diff line Loading @@ -1483,14 +1483,16 @@ TEST(MemorySanitizer, strcpy) { // NOLINT TEST(MemorySanitizer, strncpy) { // NOLINT char* x = new char[3]; char* y = new char[3]; char* y = new char[5]; x[0] = 'a'; x[1] = *GetPoisoned<char>(1, 1); x[2] = 0; strncpy(y, x, 2); // NOLINT x[2] = '\0'; strncpy(y, x, 4); // NOLINT EXPECT_NOT_POISONED(y[0]); EXPECT_POISONED(y[1]); EXPECT_POISONED(y[2]); EXPECT_NOT_POISONED(y[2]); EXPECT_NOT_POISONED(y[3]); EXPECT_POISONED(y[4]); } TEST(MemorySanitizer, stpcpy) { // NOLINT Loading