-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add several fuzz targets built when linux/mac are built with clang (#…
…20285) * Add a fuzzing target for the tlv reader * Restyle * Also enable asan for this fuzzing library * Add clang tests to targets, add build default to main build file * Restyle * Fuzzert for some chip credentials calls * A few more fuzzing calls on various things taking a bytespan * Restyle * Add a fuzz target for minmdns packet parsing * update build target after new test clang was added as a build target * Reorganize fuzz target rules into a separate file, so that build logic is shared * Restyle
- Loading branch information
Showing
10 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//build_overrides/build.gni") | ||
import("//build_overrides/chip.gni") | ||
import("${build_root}/config/compiler/compiler.gni") | ||
|
||
declare_args() { | ||
enable_fuzz_test_targets = | ||
is_clang && (current_os == "linux" || current_os == "mac") | ||
} | ||
|
||
# Define a fuzz target for chip. | ||
# | ||
# Fuzz generally only apply on the following environments: | ||
# - linux and mac host builds when using clang | ||
# | ||
# Sample usage | ||
# | ||
# chip_fuzz_target("fuzz-target-name") { | ||
# sources = [ | ||
# "FuzzTarget.cpp", # Fuzz target | ||
# ] | ||
# | ||
# public_deps = [ | ||
# "${chip_root}/src/lib/foo", # add dependencies here | ||
# "${nlunit_test_root}:nlunit-test", | ||
# ] | ||
# } | ||
# | ||
# | ||
template("chip_fuzz_target") { | ||
if (enable_fuzz_test_targets) { | ||
executable(target_name) { | ||
forward_variables_from(invoker, "*") | ||
|
||
if (defined(public_configs)) { | ||
public_configs += [ | ||
"//build/config/compiler:libfuzzer_fuzzing", | ||
"//build/config/compiler:sanitize_address", | ||
] | ||
} else { | ||
public_configs = [ | ||
"//build/config/compiler:libfuzzer_fuzzing", | ||
"//build/config/compiler:sanitize_address", | ||
] | ||
} | ||
if (!defined(oubput_dir)) { | ||
output_dir = "${root_out_dir}/tests" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
#include "credentials/CHIPCert.h" | ||
|
||
using namespace chip; | ||
using namespace chip::Credentials; | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len) | ||
{ | ||
|
||
NodeId nodeId; | ||
FabricId fabricId; | ||
|
||
ByteSpan span(data, len); | ||
|
||
(void) ExtractFabricIdFromCert(span, &fabricId); | ||
(void) ExtractNodeIdFabricIdFromOpCert(span, &nodeId, &fabricId); | ||
|
||
{ | ||
ChipDN dn; | ||
(void) ExtractSubjectDNFromX509Cert(span, dn); | ||
} | ||
|
||
{ | ||
Credentials::P256PublicKeySpan key; | ||
(void) ExtractPublicKeyFromChipCert(span, key); | ||
} | ||
|
||
{ | ||
ChipCertificateData certData; | ||
(void) DecodeChipCert(span, certData); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
#include "lib/core/CHIPTLV.h" | ||
#include "lib/core/CHIPTLVUtilities.hpp" | ||
|
||
using chip::TLV::TLVReader; | ||
|
||
static CHIP_ERROR FuzzIterator(const TLVReader & aReader, size_t aDepth, void * aContext) | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len) | ||
{ | ||
TLVReader reader; | ||
reader.Init(data, len); | ||
chip::TLV::Utilities::Iterate(reader, FuzzIterator, nullptr); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
#include <lib/dnssd/minimal_mdns/Parser.h> | ||
#include <lib/dnssd/minimal_mdns/RecordData.h> | ||
|
||
namespace { | ||
|
||
using namespace chip; | ||
using namespace mdns::Minimal; | ||
|
||
class FuzzDelegate : public ParserDelegate | ||
{ | ||
public: | ||
FuzzDelegate(const mdns::Minimal::BytesRange & packet) : mPacketRange(packet) {} | ||
virtual ~FuzzDelegate() {} | ||
|
||
void OnHeader(ConstHeaderRef & header) override {} | ||
void OnQuery(const QueryData & data) override {} | ||
void OnResource(ResourceType type, const ResourceData & data) override | ||
{ | ||
switch (data.GetType()) | ||
{ | ||
case QType::SRV: { | ||
mdns::Minimal::SrvRecord srv; | ||
(void) srv.Parse(data.GetData(), mPacketRange); | ||
break; | ||
} | ||
case QType::A: { | ||
chip::Inet::IPAddress addr; | ||
(void) mdns::Minimal::ParseARecord(data.GetData(), &addr); | ||
break; | ||
} | ||
case QType::AAAA: { | ||
chip::Inet::IPAddress addr; | ||
(void) mdns::Minimal::ParseAAAARecord(data.GetData(), &addr); | ||
break; | ||
} | ||
case QType::PTR: { | ||
mdns::Minimal::SerializedQNameIterator name; | ||
(void) mdns::Minimal::ParsePtrRecord(data.GetData(), mPacketRange, &name); | ||
break; | ||
} | ||
default: | ||
// nothing to do | ||
break; | ||
} | ||
} | ||
|
||
private: | ||
mdns::Minimal::BytesRange mPacketRange; | ||
}; | ||
|
||
} // namespace | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t len) | ||
{ | ||
|
||
BytesRange packet(data, data + len); | ||
FuzzDelegate delegate(packet); | ||
|
||
mdns::Minimal::ParsePacket(packet, &delegate); | ||
|
||
return 0; | ||
} |