-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfuzzing-test.cpp
More file actions
34 lines (28 loc) · 887 Bytes
/
fuzzing-test.cpp
File metadata and controls
34 lines (28 loc) · 887 Bytes
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
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include "hide-secret.hpp"
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
std::size_t size)
{
const std::span<const std::uint8_t> input{data, size};
const auto zeroIt = std::find(input.begin(), input.end(), 0);
if (zeroIt == input.begin() || zeroIt == input.end())
{
return 0;
}
const auto zeroPos = std::distance(input.begin(), zeroIt);
std::string text{};
text.reserve(zeroPos + 1);
text.append(reinterpret_cast<const char*>(data), zeroPos - 1);
text.push_back('\0');
std::string secret{};
secret.reserve(size - zeroPos);
secret.append(reinterpret_cast<const char*>(data + zeroPos + 1),
size - zeroPos - 1);
secret.push_back('\0');
hide_secret(text.data(), secret.data());
return 0;
}