From 578f6f9d4e04be4ffe4eb11b5948200470ab328b Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 8 May 2014 12:04:01 +0000 Subject: [PATCH] [msan] Intercept strxfrm. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208303 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/msan/msan_interceptors.cc | 19 +++++++++++++++++++ test/msan/strxfrm.cc | 15 +++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/msan/strxfrm.cc diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index 17331ee82..7162ba735 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -397,6 +397,23 @@ INTERCEPTOR(int, swprintf, void *str, uptr size, void *format, ...) { return res; } +INTERCEPTOR(SIZE_T, strxfrm, char *dest, const char *src, SIZE_T n) { + ENSURE_MSAN_INITED(); + CHECK_UNPOISONED(src, REAL(strlen)(src) + 1); + SIZE_T res = REAL(strxfrm)(dest, src, n); + if (res < n) __msan_unpoison(dest, res + 1); + return res; +} + +INTERCEPTOR(SIZE_T, strxfrm_l, char *dest, const char *src, SIZE_T n, + void *loc) { + ENSURE_MSAN_INITED(); + CHECK_UNPOISONED(src, REAL(strlen)(src) + 1); + SIZE_T res = REAL(strxfrm_l)(dest, src, n, loc); + if (res < n) __msan_unpoison(dest, res + 1); + return res; +} + #define INTERCEPTOR_STRFTIME_BODY(char_type, ret_type, func, s, ...) \ ENSURE_MSAN_INITED(); \ ret_type res = REAL(func)(s, __VA_ARGS__); \ @@ -1497,6 +1514,8 @@ void InitializeInterceptors() { INTERCEPT_FUNCTION(strtoull_l); INTERCEPT_FUNCTION(vswprintf); INTERCEPT_FUNCTION(swprintf); + INTERCEPT_FUNCTION(strxfrm); + INTERCEPT_FUNCTION(strxfrm_l); INTERCEPT_FUNCTION(strftime); INTERCEPT_FUNCTION(strftime_l); INTERCEPT_FUNCTION(__strftime_l); diff --git a/test/msan/strxfrm.cc b/test/msan/strxfrm.cc new file mode 100644 index 000000000..b930a6af6 --- /dev/null +++ b/test/msan/strxfrm.cc @@ -0,0 +1,15 @@ +// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t + +#include +#include +#include +#include + +int main(void) { + const char *p = "abcdef"; + char q[10]; + size_t n = strxfrm(q, p, sizeof(q)); + assert(n < sizeof(q)); + __msan_check_mem_is_initialized(q, n + 1); + return 0; +} -- 2.11.4.GIT