summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-05-23 11:38:08 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-05-23 11:38:08 +0000
commitb978627cb83e4a71336da25ef25efd474eaea898 (patch)
tree4604aade77d230061bb34b6ae4d6d69e1ee8d204
parentab25369d046c503e2a039e9ea8163ce54efb83a9 (diff)
downloadbcm5719-llvm-b978627cb83e4a71336da25ef25efd474eaea898.tar.gz
bcm5719-llvm-b978627cb83e4a71336da25ef25efd474eaea898.zip
[sanitizer] Intercept getsockopt.
llvm-svn: 182574
-rw-r--r--compiler-rt/lib/msan/tests/msan_test.cc12
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc20
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.cc1
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_stat.h1
5 files changed, 33 insertions, 2 deletions
diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc
index 2d61f40e93d..1e05382e4b9 100644
--- a/compiler-rt/lib/msan/tests/msan_test.cc
+++ b/compiler-rt/lib/msan/tests/msan_test.cc
@@ -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));
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index cddf527e380..ae49fc1b2d5 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -942,6 +942,23 @@ INTERCEPTOR(int, gethostbyname2_r, char *name, int af,
#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 *name, int af,
INIT_GETADDRINFO; \
INIT_GETSOCKNAME; \
INIT_GETHOSTBYNAME; \
- INIT_GETHOSTBYNAME_R;
+ INIT_GETHOSTBYNAME_R; \
+ INIT_GETSOCKOPT;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index c6063a2346a..60c7145b611 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -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
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.cc b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
index 8ba61ed304b..9676e0872e0 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.cc
@@ -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 ";
diff --git a/compiler-rt/lib/tsan/rtl/tsan_stat.h b/compiler-rt/lib/tsan/rtl/tsan_stat.h
index 8fce602654c..d5c8b438939 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_stat.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_stat.h
@@ -316,6 +316,7 @@ enum StatType {
StatInt_gethostbyname_r,
StatInt_gethostbyname2_r,
StatInt_gethostbyaddr_r,
+ StatInt_getsockopt,
// Dynamic annotations.
StatAnnotation,
OpenPOWER on IntegriCloud