[sanitizer] Intercept __xpg_strerror_r.

llvm-svn: 195839
This commit is contained in:
Evgeniy Stepanov 2013-11-27 12:29:10 +00:00
parent 085bf66e60
commit b76b687628
5 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,18 @@
// RUN: %clang_msan -std=c99 -O0 -g %s -o %t && %t
// strerror_r under a weird set of circumstances can be redirected to
// __xpg_strerror_r. Test that MSan handles this correctly.
#define _POSIX_C_SOURCE 200112
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main() {
char buf[1000];
int res = strerror_r(EINVAL, buf, sizeof(buf));
assert(!res);
volatile int z = strlen(buf);
return 0;
}

View File

@ -1848,6 +1848,21 @@ INTERCEPTOR(char *, strerror_r, int errnum, char *buf, SIZE_T buflen) {
#define INIT_STRERROR_R
#endif
#if SANITIZER_INTERCEPT_XPG_STRERROR_R
INTERCEPTOR(int, __xpg_strerror_r, int errnum, char *buf, SIZE_T buflen) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, __xpg_strerror_r, errnum, buf, buflen);
int res = REAL(__xpg_strerror_r)(errnum, buf, buflen);
// This version always returns a null-terminated string.
if (buf && buflen)
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, REAL(strlen)(buf) + 1);
return res;
}
#define INIT_XPG_STRERROR_R COMMON_INTERCEPT_FUNCTION(__xpg_strerror_r);
#else
#define INIT_XPG_STRERROR_R
#endif
#if SANITIZER_INTERCEPT_SCANDIR
typedef int (*scandir_filter_f)(const struct __sanitizer_dirent *);
typedef int (*scandir_compar_f)(const struct __sanitizer_dirent **,
@ -2895,6 +2910,7 @@ INTERCEPTOR(SSIZE_T, getdelim, char **lineptr, SIZE_T *n, int delim,
INIT_SCHED_GETAFFINITY; \
INIT_STRERROR; \
INIT_STRERROR_R; \
INIT_XPG_STRERROR_R; \
INIT_SCANDIR; \
INIT_SCANDIR64; \
INIT_GETGROUPS; \

View File

@ -120,6 +120,7 @@
# define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_STRERROR SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_STRERROR_R SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_SCANDIR SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_SCANDIR64 SI_LINUX_NOT_ANDROID
# define SANITIZER_INTERCEPT_GETGROUPS SI_NOT_WINDOWS

View File

@ -361,6 +361,7 @@ void StatOutput(u64 *stat) {
name[StatInt_sched_getaffinity] = " sched_getaffinity ";
name[StatInt_strerror] = " strerror ";
name[StatInt_strerror_r] = " strerror_r ";
name[StatInt___xpg_strerror_r] = " __xpg_strerror_r ";
name[StatInt_scandir] = " scandir ";
name[StatInt_scandir64] = " scandir64 ";
name[StatInt_getgroups] = " getgroups ";

View File

@ -356,6 +356,7 @@ enum StatType {
StatInt_sched_getaffinity,
StatInt_strerror,
StatInt_strerror_r,
StatInt___xpg_strerror_r,
StatInt_scandir,
StatInt_scandir64,
StatInt_getgroups,