Coverage Report

Created: 2024-05-13 06:25

/src/ada-url/fuzz/parse.cc
Line
Count
Source (jump to first uncovered line)
1
#include <fuzzer/FuzzedDataProvider.h>
2
#include <memory>
3
#include <string>
4
5
#include "ada.cpp"
6
#include "ada.h"
7
8
14.2k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9
14.2k
  FuzzedDataProvider fdp(data, size);
10
14.2k
  std::string source = fdp.ConsumeRandomLengthString(256);
11
14.2k
  std::string base_source = fdp.ConsumeRandomLengthString(256);
12
13
  /**
14
   * ada::parse<ada::url>
15
   */
16
14.2k
  auto out_url = ada::parse<ada::url>(source);
17
18
14.2k
  if (out_url) {
19
8.30k
    std::string input = fdp.ConsumeRandomLengthString(256);
20
8.30k
    out_url->set_protocol(input);
21
8.30k
    out_url->set_username(input);
22
8.30k
    out_url->set_password(input);
23
8.30k
    out_url->set_hostname(input);
24
8.30k
    out_url->set_host(input);
25
8.30k
    out_url->set_pathname(input);
26
8.30k
    out_url->set_search(input);
27
8.30k
    out_url->set_hash(input);
28
8.30k
    out_url->set_port(input);
29
30
    // volatile forces the compiler to store the results without undue
31
    // optimizations
32
8.30k
    volatile size_t length = 0;
33
34
    // getters
35
8.30k
    length += out_url->get_protocol().size();
36
8.30k
    length += out_url->get_username().size();
37
8.30k
    length += out_url->get_password().size();
38
8.30k
    length += out_url->get_hostname().size();
39
8.30k
    length += out_url->get_host().size();
40
8.30k
    length += out_url->get_pathname().size();
41
8.30k
    length += out_url->get_search().size();
42
8.30k
    length += out_url->get_hash().size();
43
8.30k
    length += out_url->get_origin().size();
44
8.30k
    length += out_url->get_port().size();
45
8.30k
  }
46
47
  /**
48
   * ada::parse<ada::url_aggregator>
49
   */
50
14.2k
  auto out_aggregator = ada::parse<ada::url_aggregator>(source);
51
52
14.2k
  if (out_aggregator) {
53
8.28k
    std::string input = fdp.ConsumeRandomLengthString(256);
54
8.28k
    out_aggregator->set_protocol(input);
55
8.28k
    out_aggregator->set_username(input);
56
8.28k
    out_aggregator->set_password(input);
57
8.28k
    out_aggregator->set_hostname(input);
58
8.28k
    out_aggregator->set_host(input);
59
8.28k
    out_aggregator->set_pathname(input);
60
8.28k
    out_aggregator->set_search(input);
61
8.28k
    out_aggregator->set_hash(input);
62
8.28k
    out_aggregator->set_port(input);
63
64
    // volatile forces the compiler to store the results without undue
65
    // optimizations
66
8.28k
    volatile size_t length = 0;
67
68
    // getters
69
8.28k
    length += out_aggregator->get_protocol().size();
70
8.28k
    length += out_aggregator->get_username().size();
71
8.28k
    length += out_aggregator->get_password().size();
72
8.28k
    length += out_aggregator->get_hostname().size();
73
8.28k
    length += out_aggregator->get_host().size();
74
8.28k
    length += out_aggregator->get_pathname().size();
75
8.28k
    length += out_aggregator->get_search().size();
76
8.28k
    length += out_aggregator->get_hash().size();
77
8.28k
    length += out_aggregator->get_origin().size();
78
8.28k
    length += out_aggregator->get_port().size();
79
80
    // clear methods
81
8.28k
    out_aggregator->clear_port();
82
8.28k
    out_aggregator->clear_search();
83
8.28k
    out_aggregator->clear_hash();
84
8.28k
  }
85
86
  /**
87
   * ada::can_parse
88
   */
89
14.2k
  auto base_source_view =
90
14.2k
      std::string_view(base_source.data(), base_source.length());
91
14.2k
  ada::can_parse(source);
92
14.2k
  ada::can_parse(source, &base_source_view);
93
94
  /**
95
   * ada::idna
96
   */
97
14.2k
  ada::idna::to_ascii(source);
98
14.2k
  ada::idna::to_unicode(source);
99
100
  /**
101
   * Node.js specific
102
   */
103
14.2k
  ada::href_from_file(source);
104
105
  /**
106
   * ada::url_search_params
107
   */
108
14.2k
  auto initialized = ada::url_search_params(base_source_view);
109
110
14.2k
  auto search_params = ada::url_search_params();
111
14.2k
  search_params.append(source, base_source);
112
14.2k
  search_params.set(source, base_source);
113
14.2k
  search_params.to_string();
114
14.2k
  if (!search_params.has(base_source)) {
115
14.1k
    search_params.append(base_source, source);
116
14.1k
  }
117
14.2k
  search_params.remove(source);
118
14.2k
  search_params.remove(source, base_source);
119
14.2k
  if (search_params.has(base_source, source)) {
120
14.1k
    search_params.remove(base_source);
121
14.1k
    search_params.remove(base_source, source);
122
14.1k
  }
123
124
14.2k
  auto keys = search_params.get_keys();
125
14.2k
  while (keys.has_next()) {
126
0
    keys.next();
127
0
  }
128
129
14.2k
  auto values = search_params.get_values();
130
14.2k
  while (values.has_next()) {
131
0
    values.next();
132
0
  }
133
134
14.2k
  auto entries = search_params.get_entries();
135
14.2k
  while (entries.has_next()) {
136
0
    entries.next();
137
0
  }
138
139
14.2k
  return 0;
140
14.2k
}  // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {