• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "wfd_start_fuzzer.h"
17 #include "wfd_sink.h"
18 #include "securec.h"
19 
20 namespace OHOS {
21 namespace Sharing {
CreateSinkFuzzTest(const uint8_t * data,size_t size)22     bool CreateSinkFuzzTest(const uint8_t* data, size_t size)
23     {
24         if (data == nullptr || size == 0) {
25             return false;
26         }
27         int32_t type{};
28         size_t objectSize = sizeof(type);
29         if (objectSize > size) {
30             return false;
31         }
32         errno_t ret = memcpy_s(&type, objectSize, data, objectSize);
33         if (ret != EOK) {
34             return false;
35         }
36 
37         std::shared_ptr<WfdSink> client = nullptr;
38         client = WfdSinkFactory::CreateSink(type, "wfd_start_fuzzer");
39         if (!client) {
40             SHARING_LOGE("create wfdSink client error.");
41             return false;
42         }
43 
44         if (client->Start() != 0) {
45             SHARING_LOGE("Start error.");
46             return false;
47         }
48 
49         if (client->Stop() != 0) {
50             SHARING_LOGE("Stop error.");
51             return false;
52         }
53 
54         return true;
55     }
56 } // namespace sharing
57 } // namespace OHOS
58 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
60 {
61     OHOS::Sharing::CreateSinkFuzzTest(data, size);
62     return 0;
63 }
64