Skip to content

Commit

Permalink
[msan] Skip memcpy interceptor called by gethostname
Browse files Browse the repository at this point in the history
No test as reproducer requires particular glibc build.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D88284
  • Loading branch information
vitalybuka committed Sep 25, 2020
1 parent 1bec6eb commit 152ff37
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/msan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions compiler-rt/lib/msan/tests/msan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 differ on different platforms.
extern const int errno_EOWNERDEAD;
Expand Down

0 comments on commit 152ff37

Please sign in to comment.