Skip to content

Commit 57d3866

Browse files
lemireanonrig
authored andcommitted
reduce the scope of the fuzzer (#846)
* reduce the scope of the fuzzer * lint
1 parent a0563a3 commit 57d3866

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

fuzz/url_pattern.cc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@
66
#include "ada.cpp"
77
#include "ada.h"
88

9-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9+
std::string bytesToAlphanumeric(const std::string& source) {
10+
static const char alphanumeric[] =
11+
"abcdefghijklmnopqrstuvwxyz"
12+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
13+
"0123456789";
14+
15+
std::string result;
16+
result.reserve(source.size());
17+
18+
for (char byte : source) {
19+
int index = static_cast<unsigned char>(byte) % (sizeof(alphanumeric) - 1);
20+
result.push_back(alphanumeric[index]);
21+
}
22+
23+
return result;
24+
}
25+
26+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
1027
FuzzedDataProvider fdp(data, size);
11-
std::string source = fdp.ConsumeRandomLengthString(50);
12-
std::string base_source = fdp.ConsumeRandomLengthString(50);
28+
// We do not want to trigger arbitrary regex matching.
29+
std::string source =
30+
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
31+
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
32+
std::string base_source =
33+
"/" + bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50)) + "/" +
34+
bytesToAlphanumeric(fdp.ConsumeRandomLengthString(50));
1335

1436
// Without base or options
1537
auto result = ada::parse_url_pattern(source, nullptr, nullptr);

0 commit comments

Comments
 (0)