[compiler-rt] r326852 - [sanitizer] Add interceptors for wcsxfrm, wcsxfrm_l
Adam Nemet via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 21:40:55 PST 2018
+Kuba
Both of these tests need xlocale.h on Darwin. I am not sure how typically compiler-rt tests handle such things so I just disabled these on Darwin in r326874 temporarily.
Adam
> On Mar 6, 2018, at 4:14 PM, Vitaly Buka via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: vitalybuka
> Date: Tue Mar 6 16:14:12 2018
> New Revision: 326852
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326852&view=rev
> Log:
> [sanitizer] Add interceptors for wcsxfrm, wcsxfrm_l
>
> Patch by Oliver Chang
>
> Reviewers: vitalybuka
>
> Reviewed By: vitalybuka
>
> Subscribers: llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D44133
>
> Added:
> compiler-rt/trunk/test/msan/wcsxfrm.cc
> compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsxfrm.c
> Modified:
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=326852&r1=326851&r2=326852&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Tue Mar 6 16:14:12 2018
> @@ -6529,6 +6529,41 @@ INTERCEPTOR(wchar_t *, wcsncat, wchar_t
> #define INIT_WCSCAT
> #endif
>
> +#if SANITIZER_INTERCEPT_WCSXFRM
> +INTERCEPTOR(SIZE_T, wcsxfrm, wchar_t *dest, const wchar_t *src, SIZE_T len) {
> + void *ctx;
> + COMMON_INTERCEPTOR_ENTER(ctx, wcsxfrm, dest, src, len);
> + COMMON_INTERCEPTOR_READ_RANGE(ctx, src,
> + sizeof(wchar_t) * (REAL(wcslen)(src) + 1));
> +
> + SIZE_T res = REAL(wcsxfrm)(dest, src, len);
> + if (res < len)
> + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, sizeof(wchar_t) * (res + 1));
> +
> + return res;
> +}
> +
> +INTERCEPTOR(SIZE_T, wcsxfrm_l, wchar_t *dest, const wchar_t *src, SIZE_T len,
> + void *locale) {
> + void *ctx;
> + COMMON_INTERCEPTOR_ENTER(ctx, wcsxfrm_l, dest, src, len, locale);
> + COMMON_INTERCEPTOR_READ_RANGE(ctx, src,
> + sizeof(wchar_t) * (REAL(wcslen)(src) + 1));
> +
> + SIZE_T res = REAL(wcsxfrm_l)(dest, src, len, locale);
> + if (res < len)
> + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, sizeof(wchar_t) * (res + 1));
> +
> + return res;
> +}
> +
> +#define INIT_WCSXFRM \
> + COMMON_INTERCEPT_FUNCTION(wcsxfrm); \
> + COMMON_INTERCEPT_FUNCTION(wcsxfrm_l);
> +#else
> +#define INIT_WCSXFRM
> +#endif
> +
> #if SANITIZER_INTERCEPT_ACCT
> INTERCEPTOR(int, acct, const char *file) {
> void *ctx;
> @@ -7275,6 +7310,7 @@ static void InitializeCommonInterceptors
> INIT_GETLOADAVG;
> INIT_WCSLEN;
> INIT_WCSCAT;
> + INIT_WCSXFRM;
> INIT_ACCT;
> INIT_USER_FROM_UID;
> INIT_UID_FROM_USER;
>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=326852&r1=326851&r2=326852&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Tue Mar 6 16:14:12 2018
> @@ -246,6 +246,7 @@
> #define SANITIZER_INTERCEPT_MBSNRTOWCS \
> (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
> #define SANITIZER_INTERCEPT_WCSTOMBS SI_POSIX
> +#define SANITIZER_INTERCEPT_WCSXFRM SI_POSIX
> #define SANITIZER_INTERCEPT_WCSNRTOMBS \
> (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
> #define SANITIZER_INTERCEPT_WCRTOMB \
>
> Added: compiler-rt/trunk/test/msan/wcsxfrm.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/wcsxfrm.cc?rev=326852&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/msan/wcsxfrm.cc (added)
> +++ compiler-rt/trunk/test/msan/wcsxfrm.cc Tue Mar 6 16:14:12 2018
> @@ -0,0 +1,30 @@
> +// RUN: %clangxx_msan -O0 -g %s -o %t && not %run %t
> +
> +#include <assert.h>
> +#include <locale.h>
> +#include <sanitizer/msan_interface.h>
> +#include <stdlib.h>
> +#include <wchar.h>
> +
> +int main(void) {
> + wchar_t q[10];
> + size_t n = wcsxfrm(q, L"abcdef", sizeof(q) / sizeof(wchar_t));
> + assert(n < sizeof(q));
> + __msan_check_mem_is_initialized(q, (n + 1) * sizeof(wchar_t));
> +
> + locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
> +
> + __msan_poison(&q, sizeof(q));
> + n = wcsxfrm_l(q, L"qwerty", sizeof(q) / sizeof(wchar_t), loc);
> + assert(n < sizeof(q));
> + __msan_check_mem_is_initialized(q, (n + 1) * sizeof(wchar_t));
> +
> + q[0] = 'A';
> + q[1] = '\x00';
> + __msan_poison(&q, sizeof(q));
> + wcsxfrm(NULL, q, 0);
> +
> + // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
> + // CHECK: in main {{.*}}wcsxfrm.cc:25
> + return 0;
> +}
>
> Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsxfrm.c
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsxfrm.c?rev=326852&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsxfrm.c (added)
> +++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/wcsxfrm.c Tue Mar 6 16:14:12 2018
> @@ -0,0 +1,19 @@
> +// RUN: %clang -O0 %s -o %t && %run %t
> +
> +#include <assert.h>
> +#include <locale.h>
> +#include <wchar.h>
> +
> +int main(int argc, char **argv) {
> + wchar_t q[10];
> + size_t n = wcsxfrm(q, L"abcdef", sizeof(q) / sizeof(wchar_t));
> + assert(n < sizeof(q));
> +
> + wchar_t q2[10];
> + locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0);
> + n = wcsxfrm_l(q2, L"qwerty", sizeof(q) / sizeof(wchar_t), loc);
> + assert(n < sizeof(q2));
> +
> + freelocale(loc);
> + return 0;
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list