Skip to content

Commit 1381645

Browse files
authored
[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.
1 parent 8d6469b commit 1381645

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: no-exceptions
11+
12+
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13+
14+
// XFAIL: availability-fp_to_chars-missing
15+
16+
#include <cstdint>
17+
#include <format>
18+
#include <string_view>
19+
20+
#include "fuzz.h"
21+
22+
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
23+
try {
24+
[[maybe_unused]] auto result = std::vformat(std::string_view{(const char*)(data), size}, std::make_format_args());
25+
} catch (std::format_error const&) {
26+
// If the fuzzing input isn't a valid thing we can format and we detect it, it's okay. We are looking for crashes.
27+
return 0;
28+
}
29+
return 0;
30+
}

0 commit comments

Comments
 (0)