[libc-commits] [libc] [libc] Add fuzzers for `memcpy` and `memset` (PR #90591)

Clement Courbet via libc-commits libc-commits at lists.llvm.org
Tue Apr 30 04:29:21 PDT 2024


================
@@ -0,0 +1,45 @@
+//===-- memset_fuzz.cpp ---------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// Fuzzing test for llvm-libc memcset implementation.
+///
+//===----------------------------------------------------------------------===//
+#include "protected_pages.h"
+#include "src/string/memset.h"
+#include <stddef.h> // size_t
+#include <stdint.h> // uint8_t
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t data_size) {
+  static constexpr size_t MAX_SIZE = 1024;
+  static ProtectedPages pages;
----------------
legrosbuffle wrote:

I think using msan should catch these without having to write a custom class and make the fuzz test clearer.  It should be as simple as `__msan_poison` the dst (to check we have no spurious reads) and `_msan_unpoison` the src (to allow reads). 

https://github.com/llvm/llvm-project/pull/90591


More information about the libc-commits mailing list