-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsse_parser_fuzzer.cpp
More file actions
37 lines (35 loc) · 1.14 KB
/
Copy pathsse_parser_fuzzer.cpp
File metadata and controls
37 lines (35 loc) · 1.14 KB
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
#include "fuzz_common.hpp"
#include "foundation/network/sse_parser.hh"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <string_view>
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
{
try {
const auto input = lgc::fuzz::inputToString(data, size);
lgc::SseParser parser;
std::size_t offset = 0;
while (offset < input.size()) {
const auto raw = static_cast<unsigned char>(input[offset]);
const std::size_t chunkSize = std::min<std::size_t>(
input.size() - offset,
1U + (raw % 23U));
const auto chunk = std::string_view(input).substr(offset, chunkSize);
auto status = parser.feed(
chunk,
[](const lgc::ServerSentEvent&) {
return lgc::Status::ok();
});
if (!status.isOk())
return 0;
offset += chunkSize;
}
(void)parser.finish(
[](const lgc::ServerSentEvent&) {
return lgc::Status::ok();
});
} catch (...) {
}
return 0;
}