]>
git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/fuzzing/two-args.cc
1 // Copyright (c) 2019, Paul Dreik
2 // For the license information refer to format.h.
7 #include <fmt/format.h>
9 #include "fuzzer-common.h"
11 template <typename Item1
, typename Item2
>
12 void invoke_fmt(const uint8_t* data
, size_t size
) {
13 static_assert(sizeof(Item1
) <= fixed_size
, "size1 exceeded");
14 static_assert(sizeof(Item2
) <= fixed_size
, "size2 exceeded");
15 if (size
<= fixed_size
+ fixed_size
) return;
17 const Item1 item1
= assign_from_buf
<Item1
>(data
);
21 const Item2 item2
= assign_from_buf
<Item2
>(data
);
25 auto format_str
= fmt::string_view(as_chars(data
), size
);
26 #if FMT_FUZZ_FORMAT_TO_STRING
27 std::string message
= fmt::format(format_str
, item1
, item2
);
29 fmt::memory_buffer message
;
30 fmt::format_to(message
, format_str
, item1
, item2
);
34 // For dynamic dispatching to an explicit instantiation.
35 template <typename Callback
> void invoke(int index
, Callback callback
) {
44 using sc
= signed char;
48 using uc
= unsigned char;
55 using us
= unsigned short;
68 using ul
= unsigned long;
78 using LD
= long double;
88 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
) {
89 if (size
<= 3) return 0;
91 // Switch types depending on the first byte of the input.
92 const auto type1
= data
[0] & 0x0F;
93 const auto type2
= (data
[0] & 0xF0) >> 4;
97 invoke(type1
, [=](auto param1
) {
98 invoke(type2
, [=](auto param2
) {
99 invoke_fmt
<decltype(param1
), decltype(param2
)>(data
, size
);
102 } catch (std::exception
&) {