[msan] Intercept strxfrm.

llvm-svn: 208303
This commit is contained in:
Evgeniy Stepanov 2014-05-08 12:04:01 +00:00
parent 04a71a45ff
commit c5e51926dc
2 changed files with 34 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}