diff --git a/fuzz/ada_c.c b/fuzz/ada_c.c new file mode 100644 index 000000000..edbad0489 --- /dev/null +++ b/fuzz/ada_c.c @@ -0,0 +1,65 @@ +#include "ada_c.h" + +#include +#include +#include +#include + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + /** + * ada_c + */ + ada_url out = ada_parse((char*)data, size); + bool is_valid = ada_is_valid(out); + + if (is_valid) { + ada_set_href(out, (char*)data, size); + ada_set_host(out, (char*)data, size); + ada_set_hostname(out, (char*)data, size); + ada_set_protocol(out, (char*)data, size); + ada_set_username(out, (char*)data, size); + ada_set_password(out, (char*)data, size); + ada_set_port(out, (char*)data, size); + ada_set_pathname(out, (char*)data, size); + ada_set_search(out, (char*)data, size); + ada_set_hash(out, (char*)data, size); + + ada_get_hash(out); + ada_get_host(out); + ada_get_host_type(out); + ada_get_hostname(out); + ada_get_href(out); + ada_owned_string out_get_origin = ada_get_origin(out); + ada_get_pathname(out); + ada_get_username(out); + ada_get_password(out); + ada_get_protocol(out); + ada_get_port(out); + ada_get_search(out); + ada_get_scheme_type(out); + + ada_has_credentials(out); + ada_has_empty_hostname(out); + ada_has_hostname(out); + ada_has_non_empty_username(out); + ada_has_non_empty_password(out); + ada_has_port(out); + ada_has_password(out); + ada_has_hash(out); + ada_has_search(out); + + ada_get_components(out); + + ada_clear_port(out); + ada_clear_hash(out); + ada_clear_search(out); + + ada_free_owned_string(out_get_origin); + } + + bool can_parse_result = ada_can_parse((char*)data, size); + + ada_free(out); + + return 0; +} diff --git a/fuzz/ada_c.options b/fuzz/ada_c.options new file mode 100644 index 000000000..c6aba21af --- /dev/null +++ b/fuzz/ada_c.options @@ -0,0 +1,3 @@ +[libfuzzer] +dict = url.dict +max_len = 1024 diff --git a/fuzz/build.sh b/fuzz/build.sh index 3f03d724b..eb5b8e989 100755 --- a/fuzz/build.sh +++ b/fuzz/build.sh @@ -37,4 +37,16 @@ $CXX $CFLAGS $CXXFLAGS \ $CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE url_search_params.o \ -o $OUT/url_search_params +$CXX $CFLAGS $CXXFLAGS \ + -std=c++17 \ + -I build/singleheader \ + -c build/singleheader/ada.cpp -o ada.o + +$CC $CFLAGS $CXXFLAGS \ + -I build/singleheader \ + -c fuzz/ada_c.c -o ada_c.o + +$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE ./ada.o ada_c.o \ + -o $OUT/ada_c + cp $SRC/ada-url/fuzz/*.dict $SRC/ada-url/fuzz/*.options $OUT/