• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstddef>
17 #include <cstdint>
18 
19 #include "av_trans_message.h"
20 #include "av_trans_types.h"
21 
22 #include <fuzzer/FuzzedDataProvider.h>
23 #include "daudio_sink_ctrl_trans.h"
24 #include "sourcectrltransonchannelevent_fuzzer.h"
25 #include "transport/socket.h"
26 
27 #include <dlfcn.h>
28 
29 #include "daudio_constants.h"
30 #include "daudio_errorcode.h"
31 #include "daudio_log.h"
32 #include "daudio_util.h"
33 
34 namespace OHOS {
35 namespace DistributedHardware {
SourceCtrlTransOnChannelEventFuzzTest(const uint8_t * data,size_t size)36 void SourceCtrlTransOnChannelEventFuzzTest(const uint8_t* data, size_t size)
37 {
38     if (data == nullptr || size == 0) {
39         return;
40     }
41     std::string devId = "devId";
42     std::string sessionName = "sessionName";
43     std::string peerSessName = "peerSessName";
44     auto sinkCtrlTransCb = std::make_shared<SourceCtrlTransOnChannelEventFuzzer>();
45     auto ctrlTrans = DaudioSinkCtrlTrans(devId, sessionName, peerSessName, sinkCtrlTransCb);
46     FuzzedDataProvider fdp(data, size);
47     AVTransEvent event;
48     event.content = fdp.ConsumeRandomLengthString();
49     event.peerDevId = fdp.ConsumeRandomLengthString();
50     event.type = static_cast<EventType>(fdp.ConsumeIntegral<uint32_t>());
51     ctrlTrans.OnChannelEvent(event);
52 }
53 }
54 }
55 
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59     /* Run your code on data */
60     OHOS::DistributedHardware::SourceCtrlTransOnChannelEventFuzzTest(data, size);
61     return 0;
62 }
63 
64