Skip to content

Commit 7c6910d

Browse files
authored
Fix/improve fuzzing (#2426)
1 parent e9dc035 commit 7c6910d

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

fuzz/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ distdir:
774774
-o -name '*.cpp' \
775775
-o -name '*.options' \
776776
-o -name 'ipv4_addresses.txt' \
777+
-o -name 'ipv6_addresses.txt' \
777778
-o -name 'bd_param.txt' \
778779
-o -name 'splt_param.txt' \
779780
-o -name 'random_list.list' \

fuzz/fuzz_ds_ptree.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
4949
}
5050
}
5151

52+
/* Some higher level functions */
53+
ndpi_load_ipv4_ptree_file(t, "ipv4_addresses.txt", NDPI_PROTOCOL_TLS);
54+
ndpi_load_ipv4_ptree_file(t, "invalid_filename", NDPI_PROTOCOL_TLS);
55+
ndpi_load_ipv6_ptree_file(t, "ipv6_addresses.txt", NDPI_PROTOCOL_TLS);
56+
ndpi_load_ipv6_ptree_file(t, "invalid_filename", NDPI_PROTOCOL_TLS);
57+
5258
/* Random search */
5359
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
5460
for (i = 0; i < num_iteration; i++) {

fuzz/ipv6_addresses.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Random list of ipv6 addresses
2+
3+
2001:db8:3333:4444:5555:6666:7777:8888
4+
2001:a:b:c::/64
5+
ff06::c3

src/lib/ndpi_main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ static ndpi_patricia_node_t* add_to_ptree(ndpi_patricia_tree_t *tree, int family
27352735
/* ******************************************* */
27362736

27372737
/*
2738-
Load a file containing IPv4 addresses in CIDR format as 'protocol_id'
2738+
Load a file containing IPv4 OR IPv6 addresses in CIDR format as 'protocol_id'
27392739
27402740
Return: the number of entries loaded or -1 in case of error
27412741
*/
@@ -2808,13 +2808,17 @@ int ndpi_load_ptree_file(ndpi_patricia_tree_t *ptree,
28082808

28092809
int ndpi_load_ipv4_ptree_file(ndpi_ptree_t *ptree, const char *path,
28102810
u_int16_t protocol_id) {
2811+
if(!ptree)
2812+
return -1;
28112813
return(ndpi_load_ptree_file(ptree->v4, path, true /* IPv4 */, protocol_id));
28122814
}
28132815

28142816
/* ******************************************* */
28152817

28162818
int ndpi_load_ipv6_ptree_file(ndpi_ptree_t *ptree, const char *path,
28172819
u_int16_t protocol_id) {
2820+
if(!ptree)
2821+
return -1;
28182822
return(ndpi_load_ptree_file(ptree->v6, path, false /* IPv6 */, protocol_id));
28192823
}
28202824

@@ -2827,6 +2831,8 @@ int ndpi_load_ipv6_ptree_file(ndpi_ptree_t *ptree, const char *path,
28272831
*/
28282832
int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str,
28292833
const char *path, u_int16_t protocol_id) {
2834+
if(!ndpi_str)
2835+
return -1;
28302836
return(ndpi_load_ptree_file(ndpi_str->protocols_ptree,
28312837
path, true /* is_ipv4 */,
28322838
protocol_id));

tests/ossfuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cp example/ja3_fingerprints.csv $OUT/
6161
cp example/sha1_fingerprints.csv $OUT/
6262
cp example/config.txt $OUT/
6363
cp lists/public_suffix_list.dat $OUT/
64-
cp fuzz/ipv4_addresses.txt $OUT/
64+
cp fuzz/ipv*_addresses.txt $OUT/
6565
cp fuzz/bd_param.txt $OUT/
6666
cp fuzz/splt_param.txt $OUT/
6767
cp fuzz/random_list.list $OUT/

0 commit comments

Comments
 (0)