diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp --- a/compiler-rt/lib/asan/asan_interceptors.cpp +++ b/compiler-rt/lib/asan/asan_interceptors.cpp @@ -96,6 +96,14 @@ ASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver) #define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \ ASAN_WRITE_RANGE(ctx, ptr, size) +#define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) { \ + AsanInterceptorContext *_ctx = (AsanInterceptorContext *)ctx; \ + if (_ctx) { \ + CHECK_RANGES_OVERLAP(_ctx->interceptor_name, to, size, from, size); \ + }\ + ASAN_READ_RANGE(ctx, from, size); \ + ASAN_WRITE_RANGE(ctx, to, size); \ +} #define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \ ASAN_READ_RANGE(ctx, ptr, size) #define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \ 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