From c67b77eee4b08c05638a219723a9141a65015da4 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Tue, 2 Mar 2021 15:32:38 +0000 Subject: [PATCH] Add a fuzzer test that tries to connect a PeerConnection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: none Change-Id: I975c6a4cd5c7dfc4a7689259292ea7d443d270f7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209182 Commit-Queue: Harald Alvestrand Reviewed-by: Henrik Boström Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#33369} --- pc/BUILD.gn | 268 +++++++++++++++++-------- test/fuzzers/BUILD.gn | 11 + test/fuzzers/sdp_integration_fuzzer.cc | 46 +++++ 3 files changed, 242 insertions(+), 83 deletions(-) create mode 100644 test/fuzzers/sdp_integration_fuzzer.cc diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 2899dafb05..619c2d2971 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -958,87 +958,6 @@ if (rtc_include_tests && !build_with_chromium) { ] } - rtc_library("pc_test_utils") { - testonly = true - sources = [ - "test/fake_audio_capture_module.cc", - "test/fake_audio_capture_module.h", - "test/fake_data_channel_provider.h", - "test/fake_peer_connection_base.h", - "test/fake_peer_connection_for_stats.h", - "test/fake_periodic_video_source.h", - "test/fake_periodic_video_track_source.h", - "test/fake_rtc_certificate_generator.h", - "test/fake_video_track_renderer.h", - "test/fake_video_track_source.h", - "test/frame_generator_capturer_video_track_source.h", - "test/mock_channel_interface.h", - "test/mock_data_channel.h", - "test/mock_delayable.h", - "test/mock_peer_connection_observers.h", - "test/mock_rtp_receiver_internal.h", - "test/mock_rtp_sender_internal.h", - "test/peer_connection_test_wrapper.cc", - "test/peer_connection_test_wrapper.h", - "test/rtc_stats_obtainer.h", - "test/test_sdp_strings.h", - ] - - deps = [ - ":jitter_buffer_delay", - ":jitter_buffer_delay_interface", - ":libjingle_peerconnection", - ":peerconnection", - ":rtc_pc_base", - ":rtp_receiver", - ":rtp_sender", - ":video_track_source", - "../api:audio_options_api", - "../api:create_frame_generator", - "../api:create_peerconnection_factory", - "../api:libjingle_peerconnection_api", - "../api:media_stream_interface", - "../api:rtc_error", - "../api:rtc_stats_api", - "../api:scoped_refptr", - "../api:sequence_checker", - "../api/audio:audio_mixer_api", - "../api/audio_codecs:audio_codecs_api", - "../api/task_queue", - "../api/task_queue:default_task_queue_factory", - "../api/video:builtin_video_bitrate_allocator_factory", - "../api/video:video_frame", - "../api/video:video_rtp_headers", - "../api/video_codecs:builtin_video_decoder_factory", - "../api/video_codecs:builtin_video_encoder_factory", - "../api/video_codecs:video_codecs_api", - "../call:call_interfaces", - "../media:rtc_data", - "../media:rtc_media", - "../media:rtc_media_base", - "../media:rtc_media_tests_utils", - "../modules/audio_device", - "../modules/audio_processing", - "../modules/audio_processing:api", - "../p2p:fake_port_allocator", - "../p2p:p2p_test_utils", - "../p2p:rtc_p2p", - "../rtc_base", - "../rtc_base:checks", - "../rtc_base:gunit_helpers", - "../rtc_base:rtc_base_approved", - "../rtc_base:rtc_task_queue", - "../rtc_base:task_queue_for_test", - "../rtc_base:threading", - "../rtc_base/synchronization:mutex", - "../rtc_base/task_utils:repeating_task", - "../rtc_base/third_party/sigslot", - "../test:test_support", - "../test:video_test_common", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] - } - rtc_test("peerconnection_unittests") { testonly = true sources = [ @@ -1080,8 +999,6 @@ if (rtc_include_tests && !build_with_chromium) { "sdp_serializer_unittest.cc", "stats_collector_unittest.cc", "test/fake_audio_capture_module_unittest.cc", - "test/integration_test_helpers.cc", - "test/integration_test_helpers.h", "test/test_sdp_strings.h", "track_media_info_map_unittest.cc", "video_rtp_track_source_unittest.cc", @@ -1097,6 +1014,7 @@ if (rtc_include_tests && !build_with_chromium) { ":audio_rtp_receiver", ":audio_track", ":dtmf_sender", + ":integration_test_helpers", ":jitter_buffer_delay", ":jitter_buffer_delay_interface", ":media_stream", @@ -1244,4 +1162,188 @@ if (rtc_include_tests && !build_with_chromium) { ] } } + + rtc_library("integration_test_helpers") { + testonly = true + sources = [ + "test/integration_test_helpers.cc", + "test/integration_test_helpers.h", + ] + deps = [ + ":audio_rtp_receiver", + ":audio_track", + ":dtmf_sender", + ":jitter_buffer_delay", + ":jitter_buffer_delay_interface", + ":media_stream", + ":pc_test_utils", + ":peerconnection", + ":remote_audio_source", + ":rtc_pc_base", + ":rtp_parameters_conversion", + ":rtp_receiver", + ":rtp_sender", + ":rtp_transceiver", + ":usage_pattern", + ":video_rtp_receiver", + ":video_rtp_track_source", + ":video_track", + ":video_track_source", + "../api:array_view", + "../api:audio_options_api", + "../api:callfactory_api", + "../api:create_peerconnection_factory", + "../api:fake_frame_decryptor", + "../api:fake_frame_encryptor", + "../api:function_view", + "../api:libjingle_logging_api", + "../api:libjingle_peerconnection_api", + "../api:media_stream_interface", + "../api:mock_rtp", + "../api:packet_socket_factory", + "../api:rtc_error", + "../api:rtc_stats_api", + "../api:rtp_parameters", + "../api:rtp_transceiver_direction", + "../api:scoped_refptr", + "../api/audio:audio_mixer_api", + "../api/crypto:frame_decryptor_interface", + "../api/crypto:frame_encryptor_interface", + "../api/crypto:options", + "../api/rtc_event_log", + "../api/rtc_event_log:rtc_event_log_factory", + "../api/task_queue", + "../api/task_queue:default_task_queue_factory", + "../api/transport:field_trial_based_config", + "../api/transport:webrtc_key_value_config", + "../api/transport/rtp:rtp_source", + "../api/units:time_delta", + "../api/video:builtin_video_bitrate_allocator_factory", + "../api/video:video_rtp_headers", + "../api/video_codecs:video_codecs_api", + "../call:call_interfaces", + "../call/adaptation:resource_adaptation_test_utilities", + "../logging:fake_rtc_event_log", + "../media:rtc_audio_video", + "../media:rtc_media_base", + "../media:rtc_media_config", + "../media:rtc_media_engine_defaults", + "../media:rtc_media_tests_utils", + "../modules/audio_device:audio_device_api", + "../modules/audio_processing:api", + "../modules/audio_processing:audio_processing_statistics", + "../modules/audio_processing:audioproc_test_utils", + "../modules/rtp_rtcp:rtp_rtcp_format", + "../p2p:fake_ice_transport", + "../p2p:fake_port_allocator", + "../p2p:p2p_server_utils", + "../p2p:p2p_test_utils", + "../p2p:rtc_p2p", + "../rtc_base", + "../rtc_base:checks", + "../rtc_base:gunit_helpers", + "../rtc_base:ip_address", + "../rtc_base:rtc_base_tests_utils", + "../rtc_base:rtc_json", + "../rtc_base:socket_address", + "../rtc_base:threading", + "../rtc_base:timeutils", + "../rtc_base/synchronization:mutex", + "../rtc_base/third_party/base64", + "../rtc_base/third_party/sigslot", + "../system_wrappers:metrics", + "../test:field_trial", + "../test:fileutils", + "../test:rtp_test_utils", + "../test:test_support", + "../test/pc/sctp:fake_sctp_transport", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] + } + + rtc_library("pc_test_utils") { + testonly = true + sources = [ + "test/fake_audio_capture_module.cc", + "test/fake_audio_capture_module.h", + "test/fake_data_channel_provider.h", + "test/fake_peer_connection_base.h", + "test/fake_peer_connection_for_stats.h", + "test/fake_periodic_video_source.h", + "test/fake_periodic_video_track_source.h", + "test/fake_rtc_certificate_generator.h", + "test/fake_video_track_renderer.h", + "test/fake_video_track_source.h", + "test/frame_generator_capturer_video_track_source.h", + "test/mock_channel_interface.h", + "test/mock_data_channel.h", + "test/mock_delayable.h", + "test/mock_peer_connection_observers.h", + "test/mock_rtp_receiver_internal.h", + "test/mock_rtp_sender_internal.h", + "test/peer_connection_test_wrapper.cc", + "test/peer_connection_test_wrapper.h", + "test/rtc_stats_obtainer.h", + "test/test_sdp_strings.h", + ] + + deps = [ + ":jitter_buffer_delay", + ":jitter_buffer_delay_interface", + ":libjingle_peerconnection", + ":peerconnection", + ":rtc_pc_base", + ":rtp_receiver", + ":rtp_sender", + ":video_track_source", + "../api:audio_options_api", + "../api:create_frame_generator", + "../api:create_peerconnection_factory", + "../api:libjingle_peerconnection_api", + "../api:media_stream_interface", + "../api:rtc_error", + "../api:rtc_stats_api", + "../api:scoped_refptr", + "../api:sequence_checker", + "../api/audio:audio_mixer_api", + "../api/audio_codecs:audio_codecs_api", + "../api/task_queue", + "../api/task_queue:default_task_queue_factory", + "../api/video:builtin_video_bitrate_allocator_factory", + "../api/video:video_frame", + "../api/video:video_rtp_headers", + "../api/video_codecs:builtin_video_decoder_factory", + "../api/video_codecs:builtin_video_encoder_factory", + "../api/video_codecs:video_codecs_api", + "../call:call_interfaces", + "../media:rtc_data", + "../media:rtc_media", + "../media:rtc_media_base", + "../media:rtc_media_tests_utils", + "../modules/audio_device", + "../modules/audio_processing", + "../modules/audio_processing:api", + "../p2p:fake_port_allocator", + "../p2p:p2p_test_utils", + "../p2p:rtc_p2p", + "../rtc_base", + "../rtc_base:checks", + "../rtc_base:gunit_helpers", + "../rtc_base:rtc_base_approved", + "../rtc_base:rtc_task_queue", + "../rtc_base:task_queue_for_test", + "../rtc_base:threading", + "../rtc_base/synchronization:mutex", + "../rtc_base/task_utils:repeating_task", + "../rtc_base/third_party/sigslot", + "../test:test_support", + "../test:video_test_common", + ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + } } diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn index 44387ad3f4..340c4c0dd6 100644 --- a/test/fuzzers/BUILD.gn +++ b/test/fuzzers/BUILD.gn @@ -406,6 +406,17 @@ webrtc_fuzzer_test("sdp_parser_fuzzer") { seed_corpus = "corpora/sdp-corpus" } +webrtc_fuzzer_test("sdp_integration_fuzzer") { + sources = [ "sdp_integration_fuzzer.cc" ] + deps = [ + "../../api:libjingle_peerconnection_api", + "../../pc:integration_test_helpers", + "../../pc:libjingle_peerconnection", + "../../test:test_support", + ] + seed_corpus = "corpora/sdp-corpus" +} + webrtc_fuzzer_test("stun_parser_fuzzer") { sources = [ "stun_parser_fuzzer.cc" ] deps = [ diff --git a/test/fuzzers/sdp_integration_fuzzer.cc b/test/fuzzers/sdp_integration_fuzzer.cc new file mode 100644 index 0000000000..7cae917abd --- /dev/null +++ b/test/fuzzers/sdp_integration_fuzzer.cc @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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 "pc/test/integration_test_helpers.h" + +namespace webrtc { + +class FuzzerTest : public PeerConnectionIntegrationBaseTest { + public: + FuzzerTest() + : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} + + void TestBody() override {} +}; + +void FuzzOneInput(const uint8_t* data, size_t size) { + if (size > 16384) { + return; + } + std::string message(reinterpret_cast(data), size); + + FuzzerTest test; + test.CreatePeerConnectionWrappers(); + test.ConnectFakeSignaling(); + + rtc::scoped_refptr srd_observer( + new rtc::RefCountedObject()); + + webrtc::SdpParseError error; + std::unique_ptr sdp( + CreateSessionDescription("offer", message, &error)); + // Note: This form of SRD takes ownership of the description. + test.caller()->pc()->SetRemoteDescription(srd_observer, sdp.release()); +} + +} // namespace webrtc