Skip to content
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