Skip to content

Commit

Permalink
[compiler-rt] Fix memmove/memcpy overlap detection on windows
Browse files Browse the repository at this point in the history
Summary:
The memcpy and memmove functions are the same on windows.
The overlap detection logic is incorrect.

printf-1 test:
```
stdin>:2:114: note: possible intended match here
==877412==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x0000002bf2a8,0x0000002bf2ad) and [0x0000002bf2a9, 0x0000002bf2ae) overlap
```                                                                                                                 ^

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: https://reviews.llvm.org/D22610

llvm-svn: 276299
  • Loading branch information
bergeret committed Jul 21, 2016
1 parent 3c0d8d2 commit aa76a0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler-rt/lib/asan/asan_interceptors.cc
Expand Up @@ -725,11 +725,12 @@ void InitializeAsanInterceptors() {
InitializeCommonInterceptors();

// Intercept mem* functions.
ASAN_INTERCEPT_FUNC(memcpy);
ASAN_INTERCEPT_FUNC(memset);
ASAN_INTERCEPT_FUNC(memmove);
if (PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE) {
// In asan, REAL(memmove) is not used, but it is used in msan.
ASAN_INTERCEPT_FUNC(memmove);
ASAN_INTERCEPT_FUNC(memcpy);
} else {
REAL(memcpy) = REAL(memmove);
}
CHECK(REAL(memcpy));

Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/asan/tests/asan_str_test.cc
Expand Up @@ -456,12 +456,14 @@ TEST(AddressSanitizer, StrArgsOverlapTest) {
// memmove().
#if !defined(__APPLE__) || !defined(MAC_OS_X_VERSION_10_7) || \
(MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
#if PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE
// Check "memcpy". Use Ident() to avoid inlining.
memset(str, 'z', size);
Ident(memcpy)(str + 1, str + 11, 10);
Ident(memcpy)(str, str, 0);
EXPECT_DEATH(Ident(memcpy)(str, str + 14, 15), OverlapErrorMessage("memcpy"));
EXPECT_DEATH(Ident(memcpy)(str + 14, str, 15), OverlapErrorMessage("memcpy"));
#endif
#endif

// We do not treat memcpy with to==from as a bug.
Expand Down

0 comments on commit aa76a0c

Please sign in to comment.