[msan] Intercept getutent and friends.

Differential Revision: https://reviews.llvm.org/D27791

llvm-svn: 289878
This commit is contained in:
Evgeniy Stepanov 2016-12-15 22:00:14 +00:00
parent 327188aa15
commit 40f05dcec9
5 changed files with 101 additions and 0 deletions

View File

@ -5890,6 +5890,72 @@ INTERCEPTOR(int, __lxstat64, int version, const char *path, void *buf) {
// FIXME: add other *stat interceptor
#if SANITIZER_INTERCEPT_UTMP
INTERCEPTOR(void *, getutent, int dummy) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutent, dummy);
void *res = REAL(getutent)(dummy);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmp_sz);
return res;
}
INTERCEPTOR(void *, getutid, void *ut) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutid, ut);
void *res = REAL(getutid)(ut);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmp_sz);
return res;
}
INTERCEPTOR(void *, getutline, void *ut) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutline, ut);
void *res = REAL(getutline)(ut);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmp_sz);
return res;
}
#define INIT_UTMP \
COMMON_INTERCEPT_FUNCTION(getutent); \
COMMON_INTERCEPT_FUNCTION(getutid); \
COMMON_INTERCEPT_FUNCTION(getutline);
#else
#define INIT_UTMP
#endif
#if SANITIZER_INTERCEPT_UTMPX
INTERCEPTOR(void *, getutxent, int dummy) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutxent, dummy);
void *res = REAL(getutxent)(dummy);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmpx_sz);
return res;
}
INTERCEPTOR(void *, getutxid, void *ut) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutxid, ut);
void *res = REAL(getutxid)(ut);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmpx_sz);
return res;
}
INTERCEPTOR(void *, getutxline, void *ut) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getutxline, ut);
void *res = REAL(getutxline)(ut);
if (res)
COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, __sanitizer::struct_utmpx_sz);
return res;
}
#define INIT_UTMPX \
COMMON_INTERCEPT_FUNCTION(getutxent); \
COMMON_INTERCEPT_FUNCTION(getutxid); \
COMMON_INTERCEPT_FUNCTION(getutxline);
#else
#define INIT_UTMPX
#endif
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap();
@ -6086,4 +6152,6 @@ static void InitializeCommonInterceptors() {
INIT___LXSTAT;
INIT___LXSTAT64;
// FIXME: add other *stat interceptors.
INIT_UTMP;
INIT_UTMPX;
}

View File

@ -312,4 +312,8 @@
#define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT
#define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_UTMP SI_NOT_WINDOWS
#define SANITIZER_INTERCEPT_UTMPX SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H

View File

@ -51,6 +51,7 @@
#include <termios.h>
#include <time.h>
#include <wchar.h>
#include <utmp.h>
#if !SANITIZER_IOS
#include <net/route.h>
@ -59,6 +60,7 @@
#if !SANITIZER_ANDROID
#include <sys/mount.h>
#include <sys/timeb.h>
#include <utmpx.h>
#endif
#if SANITIZER_LINUX
@ -284,6 +286,11 @@ namespace __sanitizer {
int shmctl_shm_stat = (int)SHM_STAT;
#endif
unsigned struct_utmp_sz = sizeof(struct utmp);
#if !SANITIZER_ANDROID
unsigned struct_utmpx_sz = sizeof(struct utmpx);
#endif
int map_fixed = MAP_FIXED;
int af_inet = (int)AF_INET;

View File

@ -862,6 +862,11 @@ namespace __sanitizer {
extern int shmctl_shm_stat;
#endif
extern unsigned struct_utmp_sz;
#if !SANITIZER_ANDROID
extern unsigned struct_utmpx_sz;
#endif
extern int map_fixed;
// ioctl arguments

View File

@ -0,0 +1,17 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
#include <utmp.h>
#include <utmpx.h>
#include <sanitizer/msan_interface.h>
int main(void) {
setutent();
while (struct utmp *ut = getutent())
__msan_check_mem_is_initialized(ut, sizeof(*ut));
endutent();
setutxent();
while (struct utmpx *utx = getutxent())
__msan_check_mem_is_initialized(utx, sizeof(*utx));
endutxent();
}