diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -304,7 +304,9 @@ #endif #ifndef COMMON_INTERCEPTOR_COPY_STRING -#define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) {} +#define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) { \ + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, to, size); \ +} #endif #ifndef COMMON_INTERCEPTOR_STRNDUP_IMPL diff --git a/compiler-rt/test/asan/TestCases/Posix/strlcpy-buffer-overflow.cpp b/compiler-rt/test/asan/TestCases/Posix/strlcpy-buffer-overflow.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Posix/strlcpy-buffer-overflow.cpp @@ -0,0 +1,21 @@ +// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// UNSUPPORTED: linux + +#include +#include +#include +#include + +#define ARRAY_SIZE(X) sizeof(X) / sizeof(X[0]) + +int main() { + const char src[] = "@@@@plz_copy_me@@@@"; + char *buffer = (char *)malloc(1); // Too small + strlcpy(buffer, src, ARRAY_SIZE(src)); // BOOM + // CHECK: heap-buffer-overflow + printf("should not be reached"); + // CHECK-NOT: should not be reached + free(buffer); + return 0; +} \ No newline at end of file