Skip to content

Commit 0339629

Browse files
committed
libcommon property add fuzzer
1 parent ac02cc2 commit 0339629

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ fuzzing/corpora/db_dump_seed_corpus.zip
7575
fuzzing/lib/lib_fuzz_pub_topic_check2
7676
fuzzing/lib/lib_fuzz_sub_topic_check2
7777
fuzzing/lib/lib_fuzz_utf8
78+
fuzzing/libcommon/libcommon_fuzz_property
79+
fuzzing/libcommon/libcommon_fuzz_property.pb.cc
80+
fuzzing/libcommon/libcommon_fuzz_property.pb.h
7881
fuzzing/libcommon/libcommon_fuzz_pub_topic_check2
7982
fuzzing/libcommon/libcommon_fuzz_sub_topic_check2
8083
fuzzing/libcommon/libcommon_fuzz_topic_matching

fuzzing/libcommon/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include ${R}/fuzzing/config.mk
44
.PHONY: all clean
55

66
FUZZERS:= \
7+
libcommon_fuzz_property \
78
libcommon_fuzz_pub_topic_check2 \
89
libcommon_fuzz_sub_topic_check2 \
910
libcommon_fuzz_topic_matching \
@@ -19,6 +20,13 @@ PROTOC?=/src/libprotobuf-mutator/external.protobuf/bin/protoc
1920

2021
all: $(FUZZERS)
2122

23+
libcommon_fuzz_property.pb.cc : libcommon_fuzz_property.proto
24+
$(PROTOC) --cpp_out=. $^
25+
26+
libcommon_fuzz_property : libcommon_fuzz_property.cpp libcommon_fuzz_property.pb.cc
27+
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD) $(PROTOBUF_LIBS)
28+
install $@ ${OUT}/$@
29+
2230
libcommon_fuzz_pub_topic_check2 : libcommon_fuzz_pub_topic_check2.cpp
2331
$(CXX) $(LOCAL_CXXFLAGS) $(LOCAL_CPPFLAGS) $(LOCAL_LDFLAGS) -o $@ $^ $(LOCAL_LIBADD)
2432
install $@ ${OUT}/$@
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "src/libfuzzer/libfuzzer_macro.h"
2+
3+
#include "libcommon_fuzz_property.pb.h"
4+
#include "mosquitto.h"
5+
6+
DEFINE_PROTO_FUZZER(const fuzz_property::FuzzerInput& fuzzer_input)
7+
{
8+
mosquitto_property *prop_list = nullptr;
9+
mosquitto_property *prop_copy = nullptr;
10+
11+
for(const fuzz_property::Property& property : fuzzer_input.properties()){
12+
int identifier = property.identifier();
13+
switch(property.data_case()){
14+
case fuzz_property::Property::DataCase::kUint8Value:
15+
mosquitto_property_add_byte(&prop_list, identifier, property.uint8_value() % 256);
16+
break;
17+
case fuzz_property::Property::DataCase::kUint16Value:
18+
mosquitto_property_add_int16(&prop_list, identifier, property.uint16_value() % 65536);
19+
break;
20+
case fuzz_property::Property::DataCase::kUint32Value:
21+
mosquitto_property_add_int32(&prop_list, identifier, property.uint32_value());
22+
break;
23+
case fuzz_property::Property::DataCase::kVarintValue:
24+
mosquitto_property_add_varint(&prop_list, identifier, property.varint_value());
25+
break;
26+
case fuzz_property::Property::DataCase::kBinaryValue:
27+
mosquitto_property_add_binary(&prop_list, identifier,
28+
property.binary_value().c_str(),
29+
property.binary_value().size());
30+
break;
31+
case fuzz_property::Property::DataCase::kStringValue:
32+
mosquitto_property_add_string(&prop_list, identifier, property.string_value().c_str());
33+
break;
34+
case fuzz_property::Property::DataCase::kStringpairValue:
35+
mosquitto_property_add_string_pair(&prop_list, identifier,
36+
property.stringpair_value().name().c_str(),
37+
property.stringpair_value().value().c_str());
38+
break;
39+
case fuzz_property::Property::DataCase::DATA_NOT_SET:
40+
break;
41+
}
42+
}
43+
44+
mosquitto_property_copy_all(&prop_copy, prop_list);
45+
mosquitto_property_free_all(&prop_list);
46+
mosquitto_property_free_all(&prop_copy);
47+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
syntax = "proto2";
2+
3+
package fuzz_property;
4+
5+
message Property {
6+
message StringPair {
7+
required string name = 1;
8+
required string value = 2;
9+
}
10+
11+
required uint32 identifier = 1;
12+
oneof data {
13+
uint32 uint8_value = 2;
14+
uint32 uint16_value = 3;
15+
uint32 uint32_value = 4;
16+
uint32 varint_value = 5;
17+
bytes binary_value = 6;
18+
string string_value = 7;
19+
StringPair stringpair_value = 8;
20+
}
21+
}
22+
23+
message FuzzerInput {
24+
repeated Property properties = 1;
25+
}

0 commit comments

Comments
 (0)