[compiler-rt] r261898 - [sanitizer] Fix third parameter in COMMON_INTERCEPTOR_WRITE_RANGE in recv and recvfrom interceptors.

Maxim Ostapenko via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 25 09:07:39 PST 2016


Author: chefmax
Date: Thu Feb 25 11:07:38 2016
New Revision: 261898

URL: http://llvm.org/viewvc/llvm-project?rev=261898&view=rev
Log:
[sanitizer] Fix third parameter in COMMON_INTERCEPTOR_WRITE_RANGE in recv and recvfrom interceptors.

Pass res instead of len as third parameter to COMMON_INTERCEPTOR_WRITE_RANGE,
because otherwise we can write to unrelated memory (in MSan) or get wrong report (in ASan).

Differential Revision: http://reviews.llvm.org/D17608

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
    compiler-rt/trunk/test/asan/TestCases/Linux/recvfrom.cc

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=261898&r1=261897&r2=261898&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Feb 25 11:07:38 2016
@@ -5340,7 +5340,7 @@ INTERCEPTOR(SSIZE_T, recv, int fd, void
   COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
   SSIZE_T res = REAL(recv)(fd, buf, len, flags);
   if (res > 0) {
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res);
   }
   if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
   return res;
@@ -5356,7 +5356,7 @@ INTERCEPTOR(SSIZE_T, recvfrom, int fd, v
   if (srcaddr) srcaddr_sz = *addrlen;
   SSIZE_T res = REAL(recvfrom)(fd, buf, len, flags, srcaddr, addrlen);
   if (res > 0) {
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
+    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res);
     if (srcaddr)
       COMMON_INTERCEPTOR_INITIALIZE_RANGE(srcaddr,
                                           Min((SIZE_T)*addrlen, srcaddr_sz));

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/recvfrom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/recvfrom.cc?rev=261898&r1=261897&r2=261898&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/recvfrom.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/recvfrom.cc Thu Feb 25 11:07:38 2016
@@ -33,7 +33,7 @@ static void *server_thread_udp(void *dat
     fprintf(stderr, "ERROR on binding\n");
 
   recvfrom(sockfd, buf, kBufSize, 0, NULL, NULL); // BOOM
-  // CHECK: {{WRITE of size 10 at 0x.* thread T1}}
+  // CHECK: {{WRITE of size 9 at 0x.* thread T1}}
   // CHECK: {{    #1 0x.* in server_thread_udp.*recvfrom.cc:}}[[@LINE-2]]
   // CHECK: {{Address 0x.* is located in stack of thread T1 at offset}}
   // CHECK-NEXT: in{{.*}}server_thread_udp{{.*}}recvfrom.cc




More information about the llvm-commits mailing list