Skip to content

Commit

Permalink
separate fuzzers into different files (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEduR authored May 14, 2024
1 parent a652cbc commit 2cea09f
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 48 deletions.
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;
}

0 comments on commit 2cea09f

Please sign in to comment.