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 2 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
46 changes: 46 additions & 0 deletions fuzz/ada_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#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 (out) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (out) {
if (is_valid) {

ada_get_hash(out);
ada_get_host(out);
ada_get_host_type(out);
ada_get_hostname(out);
ada_get_href(out);
ada_get_origin(out);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should free this, or it will leak and give false result

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);
}

bool can_parse_result = ada_can_parse((char*)data, size);

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