[compiler-rt] r182574 - [sanitizer] Intercept getsockopt.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu May 23 04:38:08 PDT 2013
Author: eugenis
Date: Thu May 23 06:38:08 2013
New Revision: 182574
URL: http://llvm.org/viewvc/llvm-project?rev=182574&view=rev
Log:
[sanitizer] Intercept getsockopt.
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=182574&r1=182573&r2=182574&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu May 23 06:38:08 2013
@@ -41,7 +41,6 @@
#include <sys/utsname.h>
#include <sys/mman.h>
#include <sys/vfs.h>
-#include <sys/types.h>
#include <dirent.h>
#include <pwd.h>
#include <sys/socket.h>
@@ -754,6 +753,17 @@ TEST(MemorySanitizer, gethostbyaddr_r) {
EXPECT_NOT_POISONED(err);
}
+TEST(MemorySanitizer, getsockopt) {
+ int sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ struct linger l[2];
+ socklen_t sz = sizeof(l[0]);
+ int res = getsockopt(sock, SOL_SOCKET, SO_LINGER, &l[0], &sz);
+ ASSERT_EQ(0, res);
+ ASSERT_EQ(sizeof(l[0]), sz);
+ EXPECT_NOT_POISONED(l[0]);
+ EXPECT_POISONED(*(char *)(l + 1));
+}
+
TEST(MemorySanitizer, getcwd) {
char path[PATH_MAX + 1];
char* res = getcwd(path, sizeof(path));
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=182574&r1=182573&r2=182574&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu May 23 06:38:08 2013
@@ -942,6 +942,23 @@ INTERCEPTOR(int, gethostbyname2_r, char
#define INIT_GETHOSTBYNAME_R
#endif
+#if SANITIZER_INTERCEPT_GETSOCKOPT
+INTERCEPTOR(int, getsockopt, int sockfd, int level, int optname, void *optval,
+ int *optlen) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, getsockopt, sockfd, level, optname, optval,
+ optlen);
+ if (optlen) COMMON_INTERCEPTOR_READ_RANGE(ctx, optlen, sizeof(*optlen));
+ int res = REAL(getsockopt)(sockfd, level, optname, optval, optlen);
+ if (res == 0)
+ if (optval && optlen) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, optval, *optlen);
+ return res;
+}
+#define INIT_GETSOCKOPT INTERCEPT_FUNCTION(getsockopt);
+#else
+#define INIT_GETSOCKOPT
+#endif
+
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
INIT_STRCASECMP; \
INIT_STRNCASECMP; \
@@ -968,4 +985,5 @@ INTERCEPTOR(int, gethostbyname2_r, char
INIT_GETADDRINFO; \
INIT_GETSOCKNAME; \
INIT_GETHOSTBYNAME; \
- INIT_GETHOSTBYNAME_R;
+ INIT_GETHOSTBYNAME_R; \
+ INIT_GETSOCKOPT;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=182574&r1=182573&r2=182574&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu May 23 06:38:08 2013
@@ -74,5 +74,6 @@
# define SANITIZER_INTERCEPT_GETSOCKNAME SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_GETHOSTBYNAME SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_GETHOSTBYNAME_R SI_LINUX
+# define SANITIZER_INTERCEPT_GETSOCKOPT SI_NOT_WINDOWS
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc?rev=182574&r1=182573&r2=182574&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.cc Thu May 23 06:38:08 2013
@@ -321,6 +321,7 @@ void StatOutput(u64 *stat) {
name[StatInt_gethostbyname_r] = " gethostbyname_r ";
name[StatInt_gethostbyname2_r] = " gethostbyname2_r ";
name[StatInt_gethostbyaddr_r] = " gethostbyaddr_r ";
+ name[StatInt_getsockopt] = " getsockopt ";
name[StatAnnotation] = "Dynamic annotations ";
name[StatAnnotateHappensBefore] = " HappensBefore ";
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h?rev=182574&r1=182573&r2=182574&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_stat.h Thu May 23 06:38:08 2013
@@ -316,6 +316,7 @@ enum StatType {
StatInt_gethostbyname_r,
StatInt_gethostbyname2_r,
StatInt_gethostbyaddr_r,
+ StatInt_getsockopt,
// Dynamic annotations.
StatAnnotation,
More information about the llvm-commits
mailing list