• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <stdint.h>
6 
7 #include "cast/streaming/compound_rtcp_parser.h"
8 #include "cast/streaming/frame_id.h"
9 #include "cast/streaming/rtcp_session.h"
10 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12   using openscreen::cast::CompoundRtcpParser;
13   using openscreen::cast::FrameId;
14   using openscreen::cast::RtcpSession;
15   using openscreen::cast::Ssrc;
16 
17   constexpr Ssrc kSenderSsrcInSeedCorpus = 1;
18   constexpr Ssrc kReceiverSsrcInSeedCorpus = 2;
19 
20   // Allocate the RtcpSession and CompoundRtcpParser statically (i.e., one-time
21   // init) to improve the fuzzer's execution rate. This is because RtcpSession
22   // also contains a NtpTimeConverter, which samples the system clock at
23   // construction time. There is no reason to re-construct these objects for
24   // each fuzzer test input.
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wexit-time-destructors"
27   static RtcpSession session(kSenderSsrcInSeedCorpus, kReceiverSsrcInSeedCorpus,
28                              openscreen::Clock::time_point{});
29   static CompoundRtcpParser::Client client_that_ignores_everything;
30   static CompoundRtcpParser parser(&session, &client_that_ignores_everything);
31 #pragma clang diagnostic pop
32 
33   const auto max_feedback_frame_id = FrameId::first() + 100;
34   parser.Parse(absl::Span<const uint8_t>(data, size), max_feedback_frame_id);
35 
36   return 0;
37 }
38 
39 #if defined(NEEDS_MAIN_TO_CALL_FUZZER_DRIVER)
40 
41 // Forward declarations of Clang's built-in libFuzzer driver.
42 namespace fuzzer {
43 using TestOneInputCallback = int (*)(const uint8_t* data, size_t size);
44 int FuzzerDriver(int* argc, char*** argv, TestOneInputCallback callback);
45 }  // namespace fuzzer
46 
main(int argc,char * argv[])47 int main(int argc, char* argv[]) {
48   return fuzzer::FuzzerDriver(&argc, &argv, LLVMFuzzerTestOneInput);
49 }
50 
51 #endif  // defined(NEEDS_MAIN_TO_CALL_FUZZER_DRIVER)
52