[compiler-rt] r186004 - [sanitizer] More checks in mbstowcs-like interceptors.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Jul 10 07:17:46 PDT 2013
Author: eugenis
Date: Wed Jul 10 09:17:46 2013
New Revision: 186004
URL: http://llvm.org/viewvc/llvm-project?rev=186004&view=rev
Log:
[sanitizer] More checks in mbstowcs-like interceptors.
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=186004&r1=186003&r2=186004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Wed Jul 10 09:17:46 2013
@@ -1225,6 +1225,7 @@ TEST(MemorySanitizer, wcsrtombs) {
const wchar_t *p = x;
char buff[10];
mbstate_t mbs;
+ memset(&mbs, 0, sizeof(mbs));
int res = wcsrtombs(buff, &p, 4, &mbs);
EXPECT_EQ(res, 3);
EXPECT_EQ(buff[0], 'a');
@@ -1239,6 +1240,7 @@ TEST(MemorySanitizer, wcsnrtombs) {
const wchar_t *p = x;
char buff[10];
mbstate_t mbs;
+ memset(&mbs, 0, sizeof(mbs));
int res = wcsnrtombs(buff, &p, 2, 4, &mbs);
EXPECT_EQ(res, 2);
EXPECT_EQ(buff[0], 'a');
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=186004&r1=186003&r2=186004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Jul 10 09:17:46 2013
@@ -1553,9 +1553,8 @@ INTERCEPTOR(SIZE_T, mbsrtowcs, wchar_t *
void *ps) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, mbsrtowcs, dest, src, len, ps);
- if (src) {
- COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
- }
+ if (src) COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
+ if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz);
SIZE_T res = REAL(mbsrtowcs)(dest, src, len, ps);
if (res != (SIZE_T)(-1) && dest && src) {
// This function, and several others, may or may not write the terminating
@@ -1582,6 +1581,7 @@ INTERCEPTOR(SIZE_T, mbsnrtowcs, wchar_t
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
if (nms) COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms);
}
+ if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz);
SIZE_T res = REAL(mbsnrtowcs)(dest, src, nms, len, ps);
if (res != (SIZE_T)(-1) && dest && src) {
SIZE_T write_cnt = res + !*src;
@@ -1611,9 +1611,8 @@ INTERCEPTOR(SIZE_T, wcsrtombs, char *des
void *ps) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, wcsrtombs, dest, src, len, ps);
- if (src) {
- COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
- }
+ if (src) COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
+ if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz);
SIZE_T res = REAL(wcsrtombs)(dest, src, len, ps);
if (res != (SIZE_T) - 1 && dest && src) {
SIZE_T write_cnt = res + !*src;
@@ -1638,6 +1637,7 @@ INTERCEPTOR(SIZE_T, wcsnrtombs, char *de
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src));
if (nms) COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms);
}
+ if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz);
SIZE_T res = REAL(wcsnrtombs)(dest, src, nms, len, ps);
if (res != (SIZE_T) - 1 && dest && src) {
SIZE_T write_cnt = res + !*src;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=186004&r1=186003&r2=186004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Wed Jul 10 09:17:46 2013
@@ -39,6 +39,7 @@
#include <sys/utsname.h>
#include <termios.h>
#include <time.h>
+#include <wchar.h>
#if SANITIZER_LINUX
#include <sys/mount.h>
@@ -112,6 +113,7 @@ namespace __sanitizer {
unsigned pid_t_sz = sizeof(pid_t);
unsigned timeval_sz = sizeof(timeval);
unsigned uid_t_sz = sizeof(uid_t);
+ unsigned mbstate_t_sz = sizeof(mbstate_t);
#if !SANITIZER_ANDROID
unsigned ucontext_t_sz = sizeof(ucontext_t);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=186004&r1=186003&r2=186004&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Wed Jul 10 09:17:46 2013
@@ -32,6 +32,7 @@ namespace __sanitizer {
extern unsigned pid_t_sz;
extern unsigned timeval_sz;
extern unsigned uid_t_sz;
+ extern unsigned mbstate_t_sz;
#if !SANITIZER_ANDROID
extern unsigned ucontext_t_sz;
More information about the llvm-commits
mailing list