[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
Wed Sep 1 12:01:59 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0239adac4aa0: [libc] Mark return value of memcpy in strcpy as initialized for msan. (authored by sivachandra).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109045/new/
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.370014.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210901/3cc21e73/attachment.bin>
More information about the libc-commits
mailing list