[PATCH] D31457: [asan] Add strndup/__strndup interceptors if targeting linux.

Evgenii Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 14:38:18 PDT 2017


eugenis added inline comments.


================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:314
+    COMMON_INTERCEPTOR_READ_RANGE(ctx, s, copy_length + 1);
+    COMMON_INTERCEPTOR_COPY_STRING(ctx, new_mem, s, copy_length);
+  }
----------------
MSan needs COPY_STRING for correctness. Without out, the destination buffer would be left uninitialized (poisoned). It needs to happen regardless of intercept_strndup.

Please add a test for this.


================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:329
+INTERCEPTOR(char*, __strndup, const char *s, uptr size) {
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, strndup, s, size);
----------------
Please avoid code duplication. Move the interceptor body to COMMON_INTERCEPTOR_STRNDUP_IMPL


================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:333
+  uptr copy_length = Min(size, from_length);
+  char *new_mem = (char *)WRAP(malloc)(copy_length + 1);
+  if (common_flags()->intercept_strndup) {
----------------
Hmm I have a vague recollection of tsan having problems with interceptors calling other interceptors. On the other hand, tsan interceptor for strdup calls REAL(strdup), which ends up in the malloc interceptor. Dmitry?



================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:339
+  for (uptr i; i < copy_length; i++) {
+    new_mem[i] = s[i];
+  }
----------------
internal_memcpy


https://reviews.llvm.org/D31457





More information about the llvm-commits mailing list