Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce the scope of the fuzzer #846

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions fuzz/url_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@
#include "ada.cpp"
#include "ada.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
std::string bytesToAlphanumeric(const std::string& source) {
static const char alphanumeric[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";

std::string result;
result.reserve(source.size());

for (char byte : source) {
int index = static_cast<unsigned char>(byte) % (sizeof(alphanumeric) - 1);
result.push_back(alphanumeric[index]);
}

return result;
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string source = fdp.ConsumeRandomLengthString(50);
std::string base_source = fdp.ConsumeRandomLengthString(50);
// We do not want to trigger arbitrary regex matching.
std::string source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
std::string base_source =
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));

// Without base or options
auto result = ada::parse_url_pattern(source, nullptr, nullptr);
Expand Down
Loading