Skip to content

Commit 4ddc992

Browse files
authored
improve parse fuzzer (#665)
1 parent 02402c4 commit 4ddc992

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

fuzz/parse.cc

+36-31
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,37 @@
99
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1010
FuzzedDataProvider fdp(data, size);
1111
std::string source = fdp.ConsumeRandomLengthString(256);
12-
std::string base_source = fdp.ConsumeRandomLengthString(256);
12+
13+
// volatile forces the compiler to store the results without undue
14+
// optimizations
15+
volatile size_t length = 0;
16+
17+
auto parse_url = ada::parse<ada::url>(source);
18+
auto parse_url_aggregator = ada::parse<ada::url_aggregator>(source);
19+
20+
if (parse_url) {
21+
length += parse_url->get_href().size();
22+
}
23+
24+
if (parse_url_aggregator) {
25+
length += parse_url_aggregator->get_href().size();
26+
}
1327

1428
/**
1529
* ada::parse<ada::url>
1630
*/
17-
auto out_url = ada::parse<ada::url>(source);
31+
auto out_url = ada::parse<ada::url>("https://www.ada-url.com");
1832

1933
if (out_url) {
20-
std::string input = fdp.ConsumeRandomLengthString(256);
21-
out_url->set_protocol(input);
22-
out_url->set_username(input);
23-
out_url->set_password(input);
24-
out_url->set_hostname(input);
25-
out_url->set_host(input);
26-
out_url->set_pathname(input);
27-
out_url->set_search(input);
28-
out_url->set_hash(input);
29-
out_url->set_port(input);
30-
31-
// volatile forces the compiler to store the results without undue
32-
// optimizations
33-
volatile size_t length = 0;
34+
out_url->set_protocol(source);
35+
out_url->set_username(source);
36+
out_url->set_password(source);
37+
out_url->set_hostname(source);
38+
out_url->set_host(source);
39+
out_url->set_pathname(source);
40+
out_url->set_search(source);
41+
out_url->set_hash(source);
42+
out_url->set_port(source);
3443

3544
// getters
3645
length += out_url->get_protocol().size();
@@ -48,23 +57,19 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
4857
/**
4958
* ada::parse<ada::url_aggregator>
5059
*/
51-
auto out_aggregator = ada::parse<ada::url_aggregator>(source);
60+
auto out_aggregator =
61+
ada::parse<ada::url_aggregator>("https://www.ada-url.com");
5262

5363
if (out_aggregator) {
54-
std::string input = fdp.ConsumeRandomLengthString(256);
55-
out_aggregator->set_protocol(input);
56-
out_aggregator->set_username(input);
57-
out_aggregator->set_password(input);
58-
out_aggregator->set_hostname(input);
59-
out_aggregator->set_host(input);
60-
out_aggregator->set_pathname(input);
61-
out_aggregator->set_search(input);
62-
out_aggregator->set_hash(input);
63-
out_aggregator->set_port(input);
64-
65-
// volatile forces the compiler to store the results without undue
66-
// optimizations
67-
volatile size_t length = 0;
64+
out_aggregator->set_protocol(source);
65+
out_aggregator->set_username(source);
66+
out_aggregator->set_password(source);
67+
out_aggregator->set_hostname(source);
68+
out_aggregator->set_host(source);
69+
out_aggregator->set_pathname(source);
70+
out_aggregator->set_search(source);
71+
out_aggregator->set_hash(source);
72+
out_aggregator->set_port(source);
6873

6974
// getters
7075
length += out_aggregator->get_protocol().size();

0 commit comments

Comments
 (0)