Skip to content

Commit 50ca446

Browse files
author
Maxim Ostapenko
committedFeb 25, 2016
[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 llvm-svn: 261898
1 parent be16bbc commit 50ca446

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
 

‎compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -5340,7 +5340,7 @@ INTERCEPTOR(SSIZE_T, recv, int fd, void *buf, SIZE_T len, int flags) {
53405340
COMMON_INTERCEPTOR_FD_ACCESS(ctx, fd);
53415341
SSIZE_T res = REAL(recv)(fd, buf, len, flags);
53425342
if (res > 0) {
5343-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
5343+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res);
53445344
}
53455345
if (res >= 0 && fd >= 0) COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd);
53465346
return res;
@@ -5356,7 +5356,7 @@ INTERCEPTOR(SSIZE_T, recvfrom, int fd, void *buf, SIZE_T len, int flags,
53565356
if (srcaddr) srcaddr_sz = *addrlen;
53575357
SSIZE_T res = REAL(recvfrom)(fd, buf, len, flags, srcaddr, addrlen);
53585358
if (res > 0) {
5359-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, len);
5359+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, res);
53605360
if (srcaddr)
53615361
COMMON_INTERCEPTOR_INITIALIZE_RANGE(srcaddr,
53625362
Min((SIZE_T)*addrlen, srcaddr_sz));

‎compiler-rt/test/asan/TestCases/Linux/recvfrom.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void *server_thread_udp(void *data) {
3333
fprintf(stderr, "ERROR on binding\n");
3434

3535
recvfrom(sockfd, buf, kBufSize, 0, NULL, NULL); // BOOM
36-
// CHECK: {{WRITE of size 10 at 0x.* thread T1}}
36+
// CHECK: {{WRITE of size 9 at 0x.* thread T1}}
3737
// CHECK: {{ #1 0x.* in server_thread_udp.*recvfrom.cc:}}[[@LINE-2]]
3838
// CHECK: {{Address 0x.* is located in stack of thread T1 at offset}}
3939
// CHECK-NEXT: in{{.*}}server_thread_udp{{.*}}recvfrom.cc

0 commit comments

Comments
 (0)