diff --git a/libc/src/unistd/linux/read.cpp b/libc/src/unistd/linux/read.cpp index 691a236982e37..41be1eb10c0de 100644 --- a/libc/src/unistd/linux/read.cpp +++ b/libc/src/unistd/linux/read.cpp @@ -10,7 +10,7 @@ #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" - +#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON #include "src/errno/libc_errno.h" #include // For syscall numbers. @@ -22,6 +22,9 @@ LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) { libc_errno = static_cast(-ret); return -1; } + // The cast is important since there is a check that dereferences the pointer + // which fails on void*. + MSAN_UNPOISON(reinterpret_cast(buf), count); return ret; } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 3b8ce044b7fc7..3d8c5eb178ec9 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -2599,6 +2599,7 @@ libc_function( hdrs = ["src/unistd/read.h"], deps = [ ":__support_common", + ":__support_macros_sanitizer", ":__support_osutil_syscall", ":errno", ],