Skip to content

Commit 9cd08da

Browse files
authored
Add fuzzer for C wrapper (#689)
1 parent 9517606 commit 9cd08da

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

fuzz/ada_c.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "ada_c.h"
2+
3+
#include <stdbool.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
8+
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
9+
/**
10+
* ada_c
11+
*/
12+
ada_url out = ada_parse((char*)data, size);
13+
bool is_valid = ada_is_valid(out);
14+
15+
if (is_valid) {
16+
ada_set_href(out, (char*)data, size);
17+
ada_set_host(out, (char*)data, size);
18+
ada_set_hostname(out, (char*)data, size);
19+
ada_set_protocol(out, (char*)data, size);
20+
ada_set_username(out, (char*)data, size);
21+
ada_set_password(out, (char*)data, size);
22+
ada_set_port(out, (char*)data, size);
23+
ada_set_pathname(out, (char*)data, size);
24+
ada_set_search(out, (char*)data, size);
25+
ada_set_hash(out, (char*)data, size);
26+
27+
ada_get_hash(out);
28+
ada_get_host(out);
29+
ada_get_host_type(out);
30+
ada_get_hostname(out);
31+
ada_get_href(out);
32+
ada_owned_string out_get_origin = ada_get_origin(out);
33+
ada_get_pathname(out);
34+
ada_get_username(out);
35+
ada_get_password(out);
36+
ada_get_protocol(out);
37+
ada_get_port(out);
38+
ada_get_search(out);
39+
ada_get_scheme_type(out);
40+
41+
ada_has_credentials(out);
42+
ada_has_empty_hostname(out);
43+
ada_has_hostname(out);
44+
ada_has_non_empty_username(out);
45+
ada_has_non_empty_password(out);
46+
ada_has_port(out);
47+
ada_has_password(out);
48+
ada_has_hash(out);
49+
ada_has_search(out);
50+
51+
ada_get_components(out);
52+
53+
ada_clear_port(out);
54+
ada_clear_hash(out);
55+
ada_clear_search(out);
56+
57+
ada_free_owned_string(out_get_origin);
58+
}
59+
60+
bool can_parse_result = ada_can_parse((char*)data, size);
61+
62+
ada_free(out);
63+
64+
return 0;
65+
}

fuzz/ada_c.options

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[libfuzzer]
2+
dict = url.dict
3+
max_len = 1024

fuzz/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ $CXX $CFLAGS $CXXFLAGS \
3737
$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE url_search_params.o \
3838
-o $OUT/url_search_params
3939

40+
$CXX $CFLAGS $CXXFLAGS \
41+
-std=c++17 \
42+
-I build/singleheader \
43+
-c build/singleheader/ada.cpp -o ada.o
44+
45+
$CC $CFLAGS $CXXFLAGS \
46+
-I build/singleheader \
47+
-c fuzz/ada_c.c -o ada_c.o
48+
49+
$CXX $CFLAGS $CXXFLAGS $LIB_FUZZING_ENGINE ./ada.o ada_c.o \
50+
-o $OUT/ada_c
51+
4052
cp $SRC/ada-url/fuzz/*.dict $SRC/ada-url/fuzz/*.options $OUT/

0 commit comments

Comments
 (0)