Skip to content

Commit

Permalink
Add fuzzer for C wrapper (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEduR authored Jun 18, 2024
1 parent 9517606 commit 9cd08da
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
65 changes: 65 additions & 0 deletions fuzz/ada_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "ada_c.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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;
}
3 changes: 3 additions & 0 deletions fuzz/ada_c.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[libfuzzer]
dict = url.dict
max_len = 1024
12 changes: 12 additions & 0 deletions fuzz/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/

0 comments on commit 9cd08da

Please sign in to comment.