Skip to content

Commit 04970bc

Browse files
committed
libcommon topic matching fuzzer
1 parent 30ee4a2 commit 04970bc

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ fuzzing/broker/broker_fuzz_read_handle
6767
fuzzing/broker/broker_fuzz_second_packet
6868
fuzzing/broker/broker_fuzz_second_packet_with_init
6969
fuzzing/broker/broker_fuzz_test_config
70-
7170
fuzzing/corpora/broker/*
7271
fuzzing/corpora/broker_packet_seed_corpus.zip
7372
fuzzing/corpora/client/*
@@ -76,6 +75,13 @@ fuzzing/corpora/db_dump_seed_corpus.zip
7675
fuzzing/lib/lib_fuzz_pub_topic_check2
7776
fuzzing/lib/lib_fuzz_sub_topic_check2
7877
fuzzing/lib/lib_fuzz_utf8
78+
fuzzing/libcommon/libcommon_fuzz_pub_topic_check2
79+
fuzzing/libcommon/libcommon_fuzz_sub_topic_check2
80+
fuzzing/libcommon/libcommon_fuzz_topic_matching
81+
fuzzing/libcommon/libcommon_fuzz_topic_matching.pb.cc
82+
fuzzing/libcommon/libcommon_fuzz_topic_matching.pb.h
83+
fuzzing/libcommon/libcommon_fuzz_topic_tokenise
84+
fuzzing/libcommon/libcommon_fuzz_utf8
7985
fuzzing/plugins/dynamic-security/dynsec_fuzz_load
8086

8187
lib/cpp/libmosquittopp.so*

fuzzing/libcommon/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ include ${R}/fuzzing/config.mk
66
FUZZERS:= \
77
libcommon_fuzz_pub_topic_check2 \
88
libcommon_fuzz_sub_topic_check2 \
9+
libcommon_fuzz_topic_matching \
910
libcommon_fuzz_topic_tokenise \
1011
libcommon_fuzz_utf8
1112

12-
LOCAL_CPPFLAGS+=-I${R}/include/
13+
LOCAL_CPPFLAGS+=-I${R}/include/ -I/usr/local/include/libprotobuf-mutator
1314
LOCAL_CXXFLAGS+=-g -Wall -Werror -pthread
1415
LOCAL_LDFLAGS+=
1516
LOCAL_LIBADD+=$(LIB_FUZZING_ENGINE) -lssl -lcrypto ${R}/libcommon/libmosquitto_common.a -Wl,-Bstatic -largon2 -Wl,-Bdynamic
17+
PROTOBUF_LIBS=/usr/local/lib/libprotobuf-mutator-libfuzzer.a /usr/local/lib/libprotobuf-mutator.a
1618

1719
all: $(FUZZERS)
1820

@@ -24,6 +26,13 @@ libcommon_fuzz_sub_topic_check2 : libcommon_fuzz_sub_topic_check2.cpp
2426
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
2527
install $@ ${OUT}/$@
2628

29+
libcommon_fuzz_topic_matching : libcommon_fuzz_topic_matching.cpp libcommon_fuzz_topic_matching.pb.cc
30+
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD) $(PROTOBUF_LIBS)
31+
install $@ ${OUT}/$@
32+
33+
libcommon_fuzz_topic_matching.pb.cc : libcommon_fuzz_topic_matching.proto
34+
protoc --cpp_out=. $^
35+
2736
libcommon_fuzz_topic_tokenise : libcommon_fuzz_topic_tokenise.cpp
2837
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
2938
install $@ ${OUT}/$@
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "src/libfuzzer/libfuzzer_macro.h"
2+
3+
#include "libcommon_fuzz_topic_matching.pb.h"
4+
#include "mosquitto.h"
5+
6+
DEFINE_PROTO_FUZZER(const fuzz_topic_matches_sub::FuzzerInput& fuzzer_input)
7+
{
8+
bool result;
9+
const char *string1 = fuzzer_input.string1().c_str();
10+
const char *string2 = fuzzer_input.string2().c_str();
11+
const char *username = nullptr;
12+
const char *clientid = nullptr;
13+
14+
if(fuzzer_input.has_username()){
15+
username = fuzzer_input.username().c_str();
16+
}
17+
if(fuzzer_input.has_clientid()){
18+
clientid = fuzzer_input.clientid().c_str();
19+
}
20+
21+
//targeted_function_1(fuzzer_input.arg1(), fuzzer_input.arg2(), fuzzer_input.arg3());
22+
mosquitto_topic_matches_sub(string1, string2, &result);
23+
mosquitto_topic_matches_sub2(string1, strlen(string1), string2, strlen(string2), &result);
24+
mosquitto_topic_matches_sub_with_pattern(string1, string2, clientid, username, &result);
25+
26+
mosquitto_sub_matches_acl(string1, string2, &result);
27+
mosquitto_sub_matches_acl_with_pattern(string1, string2, clientid, username, &result);
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
syntax = "proto2";
2+
3+
package fuzz_topic_matches_sub;
4+
5+
message FuzzerInput {
6+
required string string1 = 1;
7+
required string string2 = 2;
8+
optional string username = 3;
9+
optional string clientid = 4;
10+
}

fuzzing/scripts/oss-fuzz-build.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@
2121
# Note that other dependencies, i.e. sqlite are not yet built because they are
2222
# only used by plugins and not currently otherwise used.
2323
cd ${SRC}/cJSON
24-
cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_CJSON_TEST=OFF -DCMAKE_C_FLAGS=-fPIC .
24+
cmake \
25+
-DBUILD_SHARED_LIBS=OFF \
26+
-DCMAKE_C_FLAGS=-fPIC \
27+
-DENABLE_CJSON_TEST=OFF \
28+
.
29+
make
30+
make install
31+
32+
cd ${SRC}/libprotobuf-mutator
33+
cmake \
34+
-DCMAKE_C_COMPILER=clang \
35+
-DCMAKE_CXX_COMPILER=clang++ \
36+
-DCMAKE_BUILD_TYPE=Debug \
37+
-DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=ON \
38+
-DLIB_PROTO_MUTATOR_EXAMPLES=OFF \
39+
-DLIB_PROTO_MUTATOR_TESTING=OFF \
40+
.
2541
make
2642
make install
2743

fuzzing/scripts/oss-fuzz-dependencies.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@
2020
# Note that sqlite3 is required as a build dep of a plugin which is not
2121
# currently part of fuzz testing. Once it is part of fuzz testing, sqlite will
2222
# need to be built statically.
23-
apt-get update && apt-get install -y libargon2-dev libedit-dev libtool-bin make libmicrohttpd-dev libsqlite3-dev
23+
apt-get update && apt-get install -y \
24+
libargon2-dev \
25+
libedit-dev \
26+
liblzma-dev \
27+
libmicrohttpd-dev \
28+
libsqlite3-dev \
29+
libtool-bin \
30+
make \
31+
protobuf-compiler
32+
git clone https://github.com/google/libprotobuf-mutator ${SRC}/libprotobuf-mutator
2433
git clone https://github.com/ralight/cJSON ${SRC}/cJSON

0 commit comments

Comments
 (0)