From 1d4fefbbaf056492096e9e8a689550c6b7c49fe9 Mon Sep 17 00:00:00 2001 From: katrielc Date: Wed, 6 Jul 2016 08:02:00 -0700 Subject: [PATCH] Reland of https://codereview.webrtc.org/2044523002. Landing these in WebRTC under a guard so they don't build in Chromium. The guard can be removed once Chromium has migrated to use the new GN targets. BUG=webrtc:6081 NOTRY=true Review-Url: https://codereview.webrtc.org/2117183005 Cr-Commit-Position: refs/heads/master@{#13397} --- webrtc/test/fuzzers/BUILD.gn | 32 ++++++++++++++++++++ webrtc/test/fuzzers/sdp_parser_fuzzer.cc | 25 +++++++++++++++ webrtc/test/fuzzers/stun_parser_fuzzer.cc | 28 +++++++++++++++++ webrtc/test/fuzzers/stun_validator_fuzzer.cc | 23 ++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 webrtc/test/fuzzers/sdp_parser_fuzzer.cc create mode 100644 webrtc/test/fuzzers/stun_parser_fuzzer.cc create mode 100644 webrtc/test/fuzzers/stun_validator_fuzzer.cc diff --git a/webrtc/test/fuzzers/BUILD.gn b/webrtc/test/fuzzers/BUILD.gn index 9179d05cc5..9839a461d8 100644 --- a/webrtc/test/fuzzers/BUILD.gn +++ b/webrtc/test/fuzzers/BUILD.gn @@ -189,4 +189,36 @@ if (!build_with_chromium) { "../../media:media", ] } + + webrtc_fuzzer_test("sdp_parser_fuzzer") { + sources = [ + "sdp_parser_fuzzer.cc", + ] + deps = [ + "../../api:libjingle_peerconnection", + ] + seed_corpus = "corpora/sdp-corpus" + } + + webrtc_fuzzer_test("stun_parser_fuzzer") { + sources = [ + "stun_parser_fuzzer.cc", + ] + deps = [ + "../../p2p:rtc_p2p", + ] + seed_corpus = "corpora/stun-corpus" + dict = "corpora/stun.tokens" + } + + webrtc_fuzzer_test("stun_validator_fuzzer") { + sources = [ + "stun_validator_fuzzer.cc", + ] + deps = [ + "../../p2p:rtc_p2p", + ] + seed_corpus = "corpora/stun-corpus" + dict = "corpora/stun.tokens" + } } diff --git a/webrtc/test/fuzzers/sdp_parser_fuzzer.cc b/webrtc/test/fuzzers/sdp_parser_fuzzer.cc new file mode 100644 index 0000000000..f21c991a3e --- /dev/null +++ b/webrtc/test/fuzzers/sdp_parser_fuzzer.cc @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "webrtc/api/jsepsessiondescription.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + std::string message(reinterpret_cast(data), size); + webrtc::SdpParseError error; + + std::unique_ptr sdp( + CreateSessionDescription("offer", message, &error)); +} + +} // namespace webrtc diff --git a/webrtc/test/fuzzers/stun_parser_fuzzer.cc b/webrtc/test/fuzzers/stun_parser_fuzzer.cc new file mode 100644 index 0000000000..02f10b195c --- /dev/null +++ b/webrtc/test/fuzzers/stun_parser_fuzzer.cc @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "webrtc/p2p/base/stun.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + const char* message = reinterpret_cast(data); + + // Normally we'd check the integrity first, but those checks are + // fuzzed separately in stun_validator_fuzzer.cc. We still want to + // fuzz this target since the integrity checks could be forged by a + // malicious adversary who receives a call. + std::unique_ptr stun_msg(new cricket::IceMessage()); + rtc::ByteBufferReader buf(message, size); + stun_msg->Read(&buf); +} +} // namespace webrtc diff --git a/webrtc/test/fuzzers/stun_validator_fuzzer.cc b/webrtc/test/fuzzers/stun_validator_fuzzer.cc new file mode 100644 index 0000000000..1f919f59dc --- /dev/null +++ b/webrtc/test/fuzzers/stun_validator_fuzzer.cc @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include + +#include "webrtc/p2p/base/stun.h" + +namespace webrtc { +void FuzzOneInput(const uint8_t* data, size_t size) { + const char* message = reinterpret_cast(data); + + cricket::StunMessage::ValidateFingerprint(message, size); + cricket::StunMessage::ValidateMessageIntegrity(message, size, ""); +} +} // namespace webrtc