From 49151d23d92aef1f3e25b452daeb3f7531178b8a Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Mon, 13 May 2024 19:54:59 -0300 Subject: [PATCH 1/3] separate fuzzers into different files --- fuzz/can_parse.cc | 22 +++++++++++++++++ fuzz/idna.cc | 20 +++++++++++++++ fuzz/parse.cc | 48 ------------------------------------ fuzz/url_search_params.cc | 51 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 fuzz/can_parse.cc create mode 100644 fuzz/idna.cc create mode 100644 fuzz/url_search_params.cc diff --git a/fuzz/can_parse.cc b/fuzz/can_parse.cc new file mode 100644 index 000000000..9dd46f0fa --- /dev/null +++ b/fuzz/can_parse.cc @@ -0,0 +1,22 @@ +#include +#include +#include + +#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; +} \ No newline at end of file diff --git a/fuzz/idna.cc b/fuzz/idna.cc new file mode 100644 index 000000000..19010225e --- /dev/null +++ b/fuzz/idna.cc @@ -0,0 +1,20 @@ +#include +#include +#include + +#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; +} \ No newline at end of file diff --git a/fuzz/parse.cc b/fuzz/parse.cc index 8041093d1..7068f3fe6 100644 --- a/fuzz/parse.cc +++ b/fuzz/parse.cc @@ -83,58 +83,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) { diff --git a/fuzz/url_search_params.cc b/fuzz/url_search_params.cc new file mode 100644 index 000000000..f57f1cb64 --- /dev/null +++ b/fuzz/url_search_params.cc @@ -0,0 +1,51 @@ +#include +#include +#include + +#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; +} \ No newline at end of file From da7c5c9e523e3306aca82616a3a681cba40b4d57 Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Mon, 13 May 2024 20:58:11 -0300 Subject: [PATCH 2/3] run linter --- fuzz/can_parse.cc | 1 + fuzz/idna.cc | 1 + fuzz/parse.cc | 1 + fuzz/url_search_params.cc | 5 +++-- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fuzz/can_parse.cc b/fuzz/can_parse.cc index 9dd46f0fa..535e0caa1 100644 --- a/fuzz/can_parse.cc +++ b/fuzz/can_parse.cc @@ -1,4 +1,5 @@ #include + #include #include diff --git a/fuzz/idna.cc b/fuzz/idna.cc index 19010225e..1aabc3f4f 100644 --- a/fuzz/idna.cc +++ b/fuzz/idna.cc @@ -1,4 +1,5 @@ #include + #include #include diff --git a/fuzz/parse.cc b/fuzz/parse.cc index 7068f3fe6..591c15a8b 100644 --- a/fuzz/parse.cc +++ b/fuzz/parse.cc @@ -1,4 +1,5 @@ #include + #include #include diff --git a/fuzz/url_search_params.cc b/fuzz/url_search_params.cc index f57f1cb64..b12fedb9c 100644 --- a/fuzz/url_search_params.cc +++ b/fuzz/url_search_params.cc @@ -1,4 +1,5 @@ #include + #include #include @@ -14,8 +15,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { * ada::url_search_params */ -auto base_source_view = - std::string_view(base_source.data(), base_source.length()); + 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(); From 1aab4421c49325d2ced1bcf098815a6ec87db754 Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Mon, 13 May 2024 21:30:42 -0300 Subject: [PATCH 3/3] update build.sh --- fuzz/build.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fuzz/build.sh b/fuzz/build.sh index bf3765665..080c354a7 100755 --- a/fuzz/build.sh +++ b/fuzz/build.sh @@ -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