• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "connectionobserverclientimplsecond_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21 
22 #define private public
23 #define protected public
24 #include "connection_observer_client_impl.h"
25 #include "service_proxy_adapter.h"
26 #undef protected
27 #undef private
28 
29 #include "ability_fuzz_util.h"
30 #include "ability_record.h"
31 #include "continuous_task_callback_info.h"
32 #include "connection_observer.h"
33 
34 using namespace OHOS::AAFwk;
35 using namespace OHOS::AppExecFwk;
36 using namespace OHOS::AbilityRuntime;
37 
38 namespace OHOS {
39 namespace {
40 constexpr size_t STRING_MAX_LENGTH = 128;
41 }
42 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)43 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
44 {
45     auto connectionObserverClientImpl = std::make_shared<ConnectionObserverClientImpl>();
46     std::vector<ConnectionData> connectionData;
47     ConnectionData info;
48     FuzzedDataProvider fdp(data, size);
49     size_t arraySize = fdp.ConsumeIntegralInRange<size_t>(0, STRING_MAX_LENGTH);
50     for (size_t i = 0; i < arraySize; ++i) {
51         AbilityFuzzUtil::GetRandomConnectionData(fdp, info);
52         connectionData.emplace_back(info);
53     }
54     connectionObserverClientImpl->GetConnectionData(connectionData);
55     return true;
56 }
57 }
58 
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62     /* Run your code on data */
63     OHOS::DoSomethingInterestingWithMyAPI(data, size);
64     return 0;
65 }
66 
67