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