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

Add fuzzer for C wrapper #689

Merged
merged 5 commits into from
Jun 18, 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
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);
anonrig marked this conversation as resolved.
Show resolved Hide resolved
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/
Loading