[compiler-rt] 152ff37 - [msan] Skip memcpy interceptor called by gethostname

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 15:26:43 PDT 2020


Author: Vitaly Buka
Date: 2020-09-25T15:26:34-07:00
New Revision: 152ff3772c2bc4463555fb5dbb75f9b0dcc700f5

URL: https://github.com/llvm/llvm-project/commit/152ff3772c2bc4463555fb5dbb75f9b0dcc700f5
DIFF: https://github.com/llvm/llvm-project/commit/152ff3772c2bc4463555fb5dbb75f9b0dcc700f5.diff

LOG: [msan] Skip memcpy interceptor called by gethostname

No test as reproducer requires particular glibc build.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D88284

Added: 
    

Modified: 
    compiler-rt/lib/msan/msan_interceptors.cpp
    compiler-rt/lib/msan/tests/msan_test.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 6459c7a593eb8..0a17828d27106 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -827,7 +827,7 @@ INTERCEPTOR(int, prlimit64, int pid, int resource, void *new_rlimit,
 INTERCEPTOR(int, gethostname, char *name, SIZE_T len) {
   ENSURE_MSAN_INITED();
   int res = REAL(gethostname)(name, len);
-  if (!res) {
+  if (!res || (res == -1 && errno == errno_ENAMETOOLONG)) {
     SIZE_T real_len = REAL(strnlen)(name, len);
     if (real_len < len)
       ++real_len;

diff  --git a/compiler-rt/lib/msan/tests/msan_test.cpp b/compiler-rt/lib/msan/tests/msan_test.cpp
index 1ece56e665715..e0b8a6a97b6a0 100644
--- a/compiler-rt/lib/msan/tests/msan_test.cpp
+++ b/compiler-rt/lib/msan/tests/msan_test.cpp
@@ -3535,9 +3535,14 @@ TEST(MemorySanitizer, uname) {
 }
 
 TEST(MemorySanitizer, gethostname) {
-  char buf[100];
-  int res = gethostname(buf, 100);
-  ASSERT_EQ(0, res);
+  char buf[1000];
+  EXPECT_EQ(-1, gethostname(buf, 1));
+  EXPECT_EQ(ENAMETOOLONG, errno);
+  EXPECT_NOT_POISONED(buf[0]);
+  EXPECT_POISONED(buf[1]);
+
+  __msan_poison(buf, sizeof(buf));
+  EXPECT_EQ(0, gethostname(buf, sizeof(buf)));
   EXPECT_NOT_POISONED(strlen(buf));
 }
 

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h b/compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
index f388d0d364633..192e9392d494a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
@@ -24,6 +24,7 @@ namespace __sanitizer {
 #define errno_ENOMEM 12
 #define errno_EBUSY 16
 #define errno_EINVAL 22
+#define errno_ENAMETOOLONG 36
 
 // Those might not present or their value 
diff er on 
diff erent platforms.
 extern const int errno_EOWNERDEAD;


        


More information about the llvm-commits mailing list