[compiler-rt] r184735 - [sanitizer] Intercept inet_aton.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Mon Jun 24 06:56:14 PDT 2013
Author: eugenis
Date: Mon Jun 24 08:56:14 2013
New Revision: 184735
URL: http://llvm.org/viewvc/llvm-project?rev=184735&view=rev
Log:
[sanitizer] Intercept inet_aton.
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/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.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=184735&r1=184734&r2=184735&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Mon Jun 24 08:56:14 2013
@@ -1950,6 +1950,15 @@ TEST(MemorySanitizer, inet_pton) {
EXPECT_NOT_POISONED(s_out[3]);
}
+TEST(MemorySanitizer, inet_aton) {
+ const char *s = "127.0.0.1";
+ struct in_addr in[2];
+ int res = inet_aton(s, in);
+ ASSERT_NE(0, res);
+ EXPECT_NOT_POISONED(in[0]);
+ EXPECT_POISONED(*(char *)(in + 1));
+}
+
TEST(MemorySanitizer, uname) {
struct utsname u;
int res = uname(&u);
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=184735&r1=184734&r2=184735&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Mon Jun 24 08:56:14 2013
@@ -878,6 +878,23 @@ INTERCEPTOR(int, inet_pton, int af, cons
#define INIT_INET
#endif
+#if SANITIZER_INTERCEPT_INET
+INTERCEPTOR(int, inet_aton, const char *cp, void *dst) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, inet_aton, cp, dst);
+ if (cp) COMMON_INTERCEPTOR_READ_RANGE(ctx, cp, REAL(strlen)(cp) + 1);
+ int res = REAL(inet_aton)(cp, dst);
+ if (res != 0) {
+ uptr sz = __sanitizer_in_addr_sz(af_inet);
+ if (sz) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, sz);
+ }
+ return res;
+}
+#define INIT_INET_ATON INTERCEPT_FUNCTION(inet_aton);
+#else
+#define INIT_INET_ATON
+#endif
+
#if SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM
INTERCEPTOR(int, pthread_getschedparam, uptr thread, int *policy, int *param) {
void *ctx;
@@ -1275,4 +1292,5 @@ INTERCEPTOR(int, getpeername, int sockfd
INIT_MODF; \
INIT_RECVMSG; \
INIT_GETPEERNAME; \
- INIT_IOCTL;
+ INIT_IOCTL; \
+ INIT_INET_ATON;
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=184735&r1=184734&r2=184735&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Jun 24 08:56:14 2013
@@ -90,5 +90,6 @@
# define SANITIZER_INTERCEPT_RECVMSG SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_GETPEERNAME SI_NOT_WINDOWS
# define SANITIZER_INTERCEPT_IOCTL SI_NOT_WINDOWS
+# define SANITIZER_INTERCEPT_INET_ATON SI_NOT_WINDOWS
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=184735&r1=184734&r2=184735&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Mon Jun 24 08:56:14 2013
@@ -148,6 +148,9 @@ namespace __sanitizer {
return a->sa_flags & SA_SIGINFO;
}
+ int af_inet = (int)AF_INET;
+ int af_inet6 = (int)AF_INET6;
+
uptr __sanitizer_in_addr_sz(int af) {
if (af == AF_INET)
return sizeof(struct in_addr);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=184735&r1=184734&r2=184735&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Mon Jun 24 08:56:14 2013
@@ -112,6 +112,8 @@ namespace __sanitizer {
extern int e_tabsz;
#endif
+ extern int af_inet;
+ extern int af_inet6;
uptr __sanitizer_in_addr_sz(int af);
#if SANITIZER_LINUX
More information about the llvm-commits
mailing list