[compiler-rt] r208303 - [msan] Intercept strxfrm.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu May 8 05:04:01 PDT 2014


Author: eugenis
Date: Thu May  8 07:04:01 2014
New Revision: 208303

URL: http://llvm.org/viewvc/llvm-project?rev=208303&view=rev
Log:
[msan] Intercept strxfrm.

Added:
    compiler-rt/trunk/test/msan/strxfrm.cc   (with props)
Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=208303&r1=208302&r2=208303&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu May  8 07:04:01 2014
@@ -397,6 +397,23 @@ INTERCEPTOR(int, swprintf, void *str, up
   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);

Added: compiler-rt/trunk/test/msan/strxfrm.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/strxfrm.cc?rev=208303&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/strxfrm.cc (added)
+++ compiler-rt/trunk/test/msan/strxfrm.cc Thu May  8 07:04:01 2014
@@ -0,0 +1,15 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t
+
+#include <assert.h>
+#include <sanitizer/msan_interface.h>
+#include <stdlib.h>
+#include <string.h>
+
+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;
+}

Propchange: compiler-rt/trunk/test/msan/strxfrm.cc
------------------------------------------------------------------------------
    svn:eol-style = LF





More information about the llvm-commits mailing list