-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathvalidate_scan2.cc
45 lines (41 loc) · 1.04 KB
/
validate_scan2.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#define FAST_IO_SANITIZE_IO_BUFFER
#include <cstring>
#include <string>
#include <fast_io.h>
#include <fast_io_device.h>
thread_local fast_io::obuf_file obf("/dev/null");
using namespace fast_io::io;
extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const* ptr, std::size_t n) noexcept
{
fast_io::
#if defined(TEST_INADDR)
posix_in_addr
#elif defined(IPV4)
ipv4
#elif defined(TEST_IN6ADDR)
posix_in6_addr
#elif defined(IPV6)
ipv6
#else
posix_in6_addr
#endif
test_struct;
constexpr auto size_of_struct{ sizeof(test_struct) };
if (n < size_of_struct + 10)
return 0;
std::memcpy(&test_struct, ptr, size_of_struct);
auto buffer{ fast_io::concat(test_struct) };
auto buffer_size{ buffer.size() };
auto split_index{ ptr[size_of_struct + 1] };
split_index = split_index > buffer_size ? buffer_size : split_index;
std::string_view sv1{ buffer.c_str(), split_index };
std::string_view sv2{ buffer.c_str() + split_index, buffer_size - split_index };
try
{
println(obf, fast_io::to<decltype(test_struct)>(sv1, sv2));
}
catch(...)
{
}
return 0;
}