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 "clienttransudpstreaminterface_fuzzer.h"
17 
18 #include <securec.h>
19 
20 #include "client_trans_udp_stream_interface.h"
21 #include "softbus_def.h"
22 
23 namespace OHOS {
SendVtpStreamTest(const uint8_t * data,size_t size)24     void SendVtpStreamTest(const uint8_t* data, size_t size)
25     {
26         if ((data == nullptr) || (size == 0)) {
27             return;
28         }
29         StreamData *indata = nullptr;
30         StreamData *ext = nullptr;
31         StreamFrameInfo *param = nullptr;
32 
33         SendVtpStream(size, indata, ext, param);
34     }
35 
StartVtpStreamChannelServerTest(const uint8_t * data,size_t size)36     void StartVtpStreamChannelServerTest(const uint8_t* data, size_t size)
37     {
38         if ((data == nullptr) || (size == 0)) {
39             return;
40         }
41         VtpStreamOpenParam *param = nullptr;
42         IStreamListener *callback = nullptr;
43 
44         StartVtpStreamChannelServer(size, param, callback);
45     }
46 
StartVtpStreamChannelClientTest(const uint8_t * data,size_t size)47     void StartVtpStreamChannelClientTest(const uint8_t* data, size_t size)
48     {
49         if ((data == nullptr) || (size == 0)) {
50             return;
51         }
52         VtpStreamOpenParam *param = nullptr;
53         IStreamListener *callback = nullptr;
54 
55         StartVtpStreamChannelClient(size, param, callback);
56     }
57 
CloseVtpStreamChannelTest(const uint8_t * data,size_t size)58     void CloseVtpStreamChannelTest(const uint8_t* data, size_t size)
59     {
60         if ((data == nullptr) || (size < PKG_NAME_SIZE_MAX)) {
61             return;
62         }
63         char tmp[PKG_NAME_SIZE_MAX + 1] = {0};
64         if (memcpy_s(tmp, PKG_NAME_SIZE_MAX, data, PKG_NAME_SIZE_MAX) != EOK) {
65             return;
66         };
67 
68         CloseVtpStreamChannel(size, tmp);
69     }
70 } // namespace OHOS
71 
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75     /* Run your code on data */
76     OHOS::SendVtpStreamTest(data, size);
77     OHOS::StartVtpStreamChannelServerTest(data, size);
78     OHOS::StartVtpStreamChannelClientTest(data, size);
79     return 0;
80 }
81