Ada 4.1.1
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
parse.cc File Reference
#include <fuzzer/FuzzedDataProvider.h>
#include <cassert>
#include <cstdio>
#include <memory>
#include <string>
#include "ada.cpp"
#include "ada.h"

Go to the source code of this file.

Functions

bool is_valid_utf8_string (const char *buf, size_t len)
static void exercise_url_predicates (const ada::url &u)
static void exercise_aggregator_predicates (const ada::url_aggregator &u)
static std::string make_simple_absolute_candidate (FuzzedDataProvider &fdp)
static void check_href_size_invariant (const ada::url &u)
static void check_href_size_invariant (const ada::url_aggregator &u)
int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)

Function Documentation

◆ check_href_size_invariant() [1/2]

void check_href_size_invariant ( const ada::url & u)
static

Definition at line 215 of file parse.cc.

References ada::url::get_href(), and ada::url::get_href_size().

Referenced by LLVMFuzzerTestOneInput().

◆ check_href_size_invariant() [2/2]

void check_href_size_invariant ( const ada::url_aggregator & u)
static

◆ exercise_aggregator_predicates()

◆ exercise_url_predicates()

◆ is_valid_utf8_string()

bool is_valid_utf8_string ( const char * buf,
size_t len )

Definition at line 11 of file parse.cc.

Referenced by LLVMFuzzerTestOneInput().

◆ LLVMFuzzerTestOneInput()

int LLVMFuzzerTestOneInput ( const uint8_t * data,
size_t size )

Test copy and move semantics

ada::parse<ada::url>

ada::parse<ada::url_aggregator>

Relative URL parsing with base (tests the base URL resolution code path)

Chained relative URL resolution: parse source against base, then use the result as the base for a second parse. Exercises multi-level inheritance.

Known-good base URL with fuzzed relative input. Using a fixed valid base lets the fuzzer focus entropy entirely on the relative-input code paths (path resolution, query/fragment inheritance, scheme-relative URLs, etc.)

Node.js specific

Others

Sequential setter interactions with FDP-controlled ordering.

The existing code calls every setter with the same source value in a fixed order. Here we let the fuzzer choose an arbitrary sequence of setter/value pairs, checking that url and url_aggregator stay in sync after every step. This exercises setter-interaction state bugs that fixed-order testing would miss.

Re-parse idempotency.

If parse(source) succeeds, then parse(href) must also succeed and produce the same href. Serialization and parsing must be consistent: a normalized URL is always its own fixed point.

URL search params round-trip via URL integration.

Construct a URL whose query is the fuzz source, extract the search component as a url_search_params, mutate it, serialise it back, and set it on the URL. Exercises the interaction between URL objects and url_search_params and verifies that the combined pipeline doesn't crash.

Also verifies the url_search_params serialisation idempotency property: url_search_params(sp.to_string()).to_string() == sp.to_string()

Definition at line 233 of file parse.cc.

References ada::url_search_params::append(), check_href_size_invariant(), exercise_aggregator_predicates(), exercise_url_predicates(), ada::url::get_href(), ada::url_aggregator::get_href(), ada::href_from_file(), is_valid_utf8_string(), make_simple_absolute_candidate(), ada::parse(), and ada::url_search_params::to_string().

◆ make_simple_absolute_candidate()

std::string make_simple_absolute_candidate ( FuzzedDataProvider & fdp)
static

Definition at line 153 of file parse.cc.

References kFrags, kHosts, kPaths, kQueries, and kSchemes.

Referenced by LLVMFuzzerTestOneInput().