Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate fuzzers into different files #655

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions fuzz/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,27 @@ $CXX $CFLAGS $CXXFLAGS \

$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE parse.o \
-o $OUT/parse

$CXX $CFLAGS $CXXFLAGS \
-std=c++17 \
-I build/singleheader \
-c fuzz/can_parse.cc -o can_parse.o

$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE can_parse.o \
-o $OUT/can_parse

$CXX $CFLAGS $CXXFLAGS \
-std=c++17 \
-I build/singleheader \
-c fuzz/idna.cc -o idna.o

$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE idna.o \
-o $OUT/idna

$CXX $CFLAGS $CXXFLAGS \
-std=c++17 \
-I build/singleheader \
-c fuzz/url_search_params.cc -o url_search_params.o

$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE url_search_params.o \
-o $OUT/url_search_params
23 changes: 23 additions & 0 deletions fuzz/can_parse.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <fuzzer/FuzzedDataProvider.h>

#include <memory>
#include <string>

#include "ada.cpp"
#include "ada.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string source = fdp.ConsumeRandomLengthString(256);
std::string base_source = fdp.ConsumeRandomLengthString(256);

/**
* ada::can_parse
*/
auto base_source_view =
std::string_view(base_source.data(), base_source.length());
ada::can_parse(source);
ada::can_parse(source, &base_source_view);

return 0;
}
21 changes: 21 additions & 0 deletions fuzz/idna.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <fuzzer/FuzzedDataProvider.h>

#include <memory>
#include <string>

#include "ada.cpp"
#include "ada.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string source = fdp.ConsumeRandomLengthString(256);
std::string base_source = fdp.ConsumeRandomLengthString(256);

/**
* ada::idna
*/
ada::idna::to_ascii(source);
ada::idna::to_unicode(source);

return 0;
}
49 changes: 1 addition & 48 deletions fuzz/parse.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <fuzzer/FuzzedDataProvider.h>

#include <memory>
#include <string>

Expand Down Expand Up @@ -83,58 +84,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
out_aggregator->clear_hash();
}

/**
* ada::can_parse
*/
auto base_source_view =
std::string_view(base_source.data(), base_source.length());
ada::can_parse(source);
ada::can_parse(source, &base_source_view);

/**
* ada::idna
*/
ada::idna::to_ascii(source);
ada::idna::to_unicode(source);

/**
* Node.js specific
*/
ada::href_from_file(source);

/**
* ada::url_search_params
*/
auto initialized = ada::url_search_params(base_source_view);

auto search_params = ada::url_search_params();
search_params.append(source, base_source);
search_params.set(source, base_source);
search_params.to_string();
if (!search_params.has(base_source)) {
search_params.append(base_source, source);
}
search_params.remove(source);
search_params.remove(source, base_source);
if (search_params.has(base_source, source)) {
search_params.remove(base_source);
search_params.remove(base_source, source);
}

auto keys = search_params.get_keys();
while (keys.has_next()) {
keys.next();
}

auto values = search_params.get_values();
while (values.has_next()) {
values.next();
}

auto entries = search_params.get_entries();
while (entries.has_next()) {
entries.next();
}

return 0;
} // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
52 changes: 52 additions & 0 deletions fuzz/url_search_params.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <fuzzer/FuzzedDataProvider.h>

#include <memory>
#include <string>

#include "ada.cpp"
#include "ada.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fdp(data, size);
std::string source = fdp.ConsumeRandomLengthString(256);
std::string base_source = fdp.ConsumeRandomLengthString(256);

/**
* ada::url_search_params
*/

auto base_source_view =
std::string_view(base_source.data(), base_source.length());
auto initialized = ada::url_search_params(base_source_view);

auto search_params = ada::url_search_params();
search_params.append(source, base_source);
search_params.set(source, base_source);
search_params.to_string();
if (!search_params.has(base_source)) {
search_params.append(base_source, source);
}
search_params.remove(source);
search_params.remove(source, base_source);
if (search_params.has(base_source, source)) {
search_params.remove(base_source);
search_params.remove(base_source, source);
}

auto keys = search_params.get_keys();
while (keys.has_next()) {
keys.next();
}

auto values = search_params.get_values();
while (values.has_next()) {
values.next();
}

auto entries = search_params.get_entries();
while (entries.has_next()) {
entries.next();
}

return 0;
}
Loading