[libc-commits] [PATCH] D109045: [libc] Mark return value of memcpy in strcpy as initialized for msan.
Siva Chandra via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Aug 31 23:54:40 PDT 2021
sivachandra created this revision.
sivachandra added a reviewer: michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
sivachandra requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109045
Files:
libc/src/string/strcpy.cpp
Index: libc/src/string/strcpy.cpp
===================================================================
--- libc/src/string/strcpy.cpp
+++ libc/src/string/strcpy.cpp
@@ -11,13 +11,25 @@
#include "src/string/string_utils.h"
#include "src/__support/common.h"
+#include "src/__support/sanitizer.h"
namespace __llvm_libc {
LLVM_LIBC_FUNCTION(char *, strcpy,
(char *__restrict dest, const char *__restrict src)) {
- return reinterpret_cast<char *>(
- __llvm_libc::memcpy(dest, src, internal::string_length(src) + 1));
+ size_t size = internal::string_length(src) + 1;
+ char *result = reinterpret_cast<char *>(__llvm_libc::memcpy(dest, src, size));
+
+ // In many libc uses, we do not want memcpy to be instrumented. Hence,
+ // we mark the destination as initialized.
+ //
+ // We do not want memcpy to be instrumented because compilers can potentially
+ // generate calls to memcpy. If the sanitizer business logic ends up with a
+ // compiler generated call to memcpy which is instrumented, then it will
+ // break the sanitizers.
+ SANITIZER_MEMORY_INITIALIZED(result, size);
+
+ return result;
}
} // namespace __llvm_libc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109045.369867.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210901/6d8375a3/attachment.bin>
More information about the libc-commits
mailing list