[libcxx-commits] [libcxx] 1381645 - [libc++][format] adds a basic fuzzer test. (#87883)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Apr 9 10:08:44 PDT 2024
Author: Mark de Wever
Date: 2024-04-09T19:08:40+02:00
New Revision: 1381645ab675d1edcc0eaa0b72729b9f3f02a82d
URL: https://github.com/llvm/llvm-project/commit/1381645ab675d1edcc0eaa0b72729b9f3f02a82d
DIFF: https://github.com/llvm/llvm-project/commit/1381645ab675d1edcc0eaa0b72729b9f3f02a82d.diff
LOG: [libc++][format] adds a basic fuzzer test. (#87883)
This adds an initial fuzzer. Different formatting arguments will execute
different code paths. This will be tested by different fuzzer tests.
The code is based on a sample provided by Louis.
Added:
libcxx/test/libcxx/fuzzing/format_no_args.pass.cpp
Modified:
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/fuzzing/format_no_args.pass.cpp b/libcxx/test/libcxx/fuzzing/format_no_args.pass.cpp
new file mode 100644
index 00000000000000..2faf27eda98c58
--- /dev/null
+++ b/libcxx/test/libcxx/fuzzing/format_no_args.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-exceptions
+
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// XFAIL: availability-fp_to_chars-missing
+
+#include <cstdint>
+#include <format>
+#include <string_view>
+
+#include "fuzz.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
+ try {
+ [[maybe_unused]] auto result = std::vformat(std::string_view{(const char*)(data), size}, std::make_format_args());
+ } catch (std::format_error const&) {
+ // If the fuzzing input isn't a valid thing we can format and we detect it, it's okay. We are looking for crashes.
+ return 0;
+ }
+ return 0;
+}
More information about the libcxx-commits
mailing list