[PATCH] D54078: Implement getpeername(2) interceptor

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 7 12:13:28 PST 2018


vitalybuka added a comment.

Could you please fix TEST_P(MemorySanitizerIpTest, accept) so that old version fail on poisoned addrlen?



================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:3084
   COMMON_INTERCEPTOR_ENTER(ctx, getpeername, sockfd, addr, addrlen);
-  unsigned addr_sz;
-  if (addrlen) addr_sz = *addrlen;
-  // FIXME: under ASan the call below may write to freed memory and corrupt
-  // its metadata. See
-  // https://github.com/google/sanitizers/issues/321.
-  int res = REAL(getpeername)(sockfd, addr, addrlen);
-  if (!res && addr && addrlen)
-    COMMON_INTERCEPTOR_WRITE_RANGE(ctx, addr, Min(addr_sz, *addrlen));
+  __sanitizer_socklen_t taddrlen;
+  if (addrlen)
----------------
Why this and previous versions need temp taddrlen?




================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:3090
+  __sanitizer_sockaddr_storage taddr;
+  int res = REAL(getpeername)(sockfd, addr ? &taddr : 0,
+                              addrlen ? &taddrlen : 0);
----------------
should we 
```
if (addr)
  COMMON_INTERCEPTOR_READ_RANGE(ctx, addrlen, sizeof(*addrlen));
```

before calling REAL


Repository:
  rL LLVM

https://reviews.llvm.org/D54078





More information about the llvm-commits mailing list