|
| 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 | +} |
0 commit comments