[msan] Intercept openpty and forkpty.

llvm-svn: 245345
This commit is contained in:
Evgeniy Stepanov 2015-08-18 20:36:48 +00:00
parent 775d905644
commit 35b0eaf23d
2 changed files with 43 additions and 0 deletions

View File

@ -1335,6 +1335,28 @@ INTERCEPTOR(int, fork, void) {
return pid;
}
INTERCEPTOR(int, openpty, int *amaster, int *aslave, char *name,
const void *termp, const void *winp) {
ENSURE_MSAN_INITED();
InterceptorScope interceptor_scope;
int res = REAL(openpty)(amaster, aslave, name, termp, winp);
if (!res) {
__msan_unpoison(amaster, sizeof(*amaster));
__msan_unpoison(aslave, sizeof(*aslave));
}
return res;
}
INTERCEPTOR(int, forkpty, int *amaster, char *name, const void *termp,
const void *winp) {
ENSURE_MSAN_INITED();
InterceptorScope interceptor_scope;
int res = REAL(forkpty)(amaster, name, termp, winp);
if (res != -1)
__msan_unpoison(amaster, sizeof(*amaster));
return res;
}
struct MSanInterceptorContext {
bool in_interceptor_scope;
};
@ -1599,6 +1621,8 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(__cxa_atexit);
INTERCEPT_FUNCTION(shmat);
INTERCEPT_FUNCTION(fork);
INTERCEPT_FUNCTION(openpty);
INTERCEPT_FUNCTION(forkpty);
inited = 1;
}

View File

@ -0,0 +1,19 @@
// RUN: %clangxx_msan -O0 -g %s -lutil -o %t && %run %t
// RUN: %clangxx_msan -O0 -g %s -Wl,-as-needed -lutil -o %t && %run %t
#include <assert.h>
#include <pty.h>
#include <sanitizer/msan_interface.h>
int
main (int argc, char** argv)
{
int master, slave;
openpty(&master, &slave, NULL, NULL, NULL);
assert(__msan_test_shadow(&master, sizeof(master)) == -1);
assert(__msan_test_shadow(&slave, sizeof(slave)) == -1);
int master2;
forkpty(&master2, NULL, NULL, NULL);
assert(__msan_test_shadow(&master2, sizeof(master2)) == -1);
}