]> git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/fuzzing/chrono-timepoint.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / fmt / test / fuzzing / chrono-timepoint.cc
1 // Copyright (c) 2021, Paul Dreik
2 // For license information refer to format.h.
3 #include <fmt/chrono.h>
4
5 #include "fuzzer-common.h"
6
7 /*
8 * a fuzzer for the chrono timepoints formatters
9 * C is a clock (std::chrono::system_clock etc)
10 */
11 template <typename C> void doit(const uint8_t* data, size_t size) {
12 using Rep = typename C::time_point::rep;
13 constexpr auto N = sizeof(Rep);
14 if (size < N) return;
15
16 const auto x = assign_from_buf<Rep>(data);
17 typename C::duration dur{x};
18 typename C::time_point timepoint{dur};
19 data += N;
20 size -= N;
21 data_to_string format_str(data, size);
22
23 std::string message = fmt::format(format_str.get(), timepoint);
24 }
25
26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
27 try {
28 doit<std::chrono::system_clock>(data, size);
29 } catch (...) {
30 }
31 return 0;
32 }