Ada 2.7.8
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
parse.cc
Go to the documentation of this file.
1#include <fuzzer/FuzzedDataProvider.h>
2
3#include <memory>
4#include <string>
5
6#include "ada.cpp"
7#include "ada.h"
8
9extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
10 FuzzedDataProvider fdp(data, size);
11 std::string source = fdp.ConsumeRandomLengthString(256);
12 std::string base_source = fdp.ConsumeRandomLengthString(256);
13
17 auto out_url = ada::parse<ada::url>(source);
18
19 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
35 // getters
36 length += out_url->get_protocol().size();
37 length += out_url->get_username().size();
38 length += out_url->get_password().size();
39 length += out_url->get_hostname().size();
40 length += out_url->get_host().size();
41 length += out_url->get_pathname().size();
42 length += out_url->get_search().size();
43 length += out_url->get_hash().size();
44 length += out_url->get_origin().size();
45 length += out_url->get_port().size();
46 }
47
51 auto out_aggregator = ada::parse<ada::url_aggregator>(source);
52
53 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;
68
69 // getters
70 length += out_aggregator->get_protocol().size();
71 length += out_aggregator->get_username().size();
72 length += out_aggregator->get_password().size();
73 length += out_aggregator->get_hostname().size();
74 length += out_aggregator->get_host().size();
75 length += out_aggregator->get_pathname().size();
76 length += out_aggregator->get_search().size();
77 length += out_aggregator->get_hash().size();
78 length += out_aggregator->get_origin().size();
79 length += out_aggregator->get_port().size();
80
81 // clear methods
82 out_aggregator->clear_port();
83 out_aggregator->clear_search();
84 out_aggregator->clear_hash();
85 }
86
90 ada::href_from_file(source);
91
92 return 0;
93} // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Includes all definitions for Ada.
std::string href_from_file(std::string_view path)
ada_warn_unused ada::result< result_type > parse(std::string_view input, const result_type *base_url=nullptr)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Definition parse.cc:9