From ffffbefa437a00ca44f0a925c0ff73ae38f1a936 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 23 Jan 2013 10:43:38 +0000 Subject: [PATCH] [msan] gethostbyname interceptor. llvm-svn: 173249 --- compiler-rt/lib/msan/msan_interceptors.cc | 13 +++++++++++++ compiler-rt/lib/msan/tests/msan_test.cc | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc index 102e61a6d4f8..f64f443187db 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cc +++ b/compiler-rt/lib/msan/msan_interceptors.cc @@ -612,6 +612,18 @@ INTERCEPTOR(int, uname, void *utsname) { return res; } +INTERCEPTOR(int, gethostname, char *name, SIZE_T len) { + ENSURE_MSAN_INITED(); + int res = REAL(gethostname)(name, len); + if (!res) { + SIZE_T real_len = REAL(strnlen)(name, len); + if (real_len < len) + ++real_len; + __msan_unpoison(name, real_len); + } + return res; +} + INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents, int timeout) { ENSURE_MSAN_INITED(); @@ -936,6 +948,7 @@ void InitializeInterceptors() { INTERCEPT_FUNCTION(statfs64); INTERCEPT_FUNCTION(fstatfs64); INTERCEPT_FUNCTION(uname); + INTERCEPT_FUNCTION(gethostname); INTERCEPT_FUNCTION(epoll_wait); INTERCEPT_FUNCTION(epoll_pwait); INTERCEPT_FUNCTION(recv); diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index 4401848f5312..f65d6f9bff77 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -1306,6 +1306,13 @@ TEST(MemorySanitizer, uname) { EXPECT_NOT_POISONED(strlen(u.machine)); } +TEST(MemorySanitizer, gethostname) { + char buf[100]; + int res = gethostname(buf, 100); + assert(!res); + EXPECT_NOT_POISONED(strlen(buf)); +} + template static bool applySlt(T value, T shadow) { __msan_partial_poison(&value, &shadow, sizeof(T)); -- 2.34.1