[sanitizer] More checks in mbstowcs-like interceptors.

llvm-svn: 186004
This commit is contained in:
Evgeniy Stepanov 2013-07-10 14:17:46 +00:00
parent b10cbc45ad
commit 9240838655
4 changed files with 11 additions and 6 deletions

View File

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

View File

@ -1553,9 +1553,8 @@ INTERCEPTOR(SIZE_T, mbsrtowcs, wchar_t *dest, const char **src, SIZE_T len,
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 *dest, const char **src, SIZE_T nms,
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 *dest, const wchar_t **src, SIZE_T len,
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 *dest, const wchar_t **src, SIZE_T nms,
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;

View File

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

View File

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