• 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 "connectionobserverclientimplthird_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     ConnectionData info;
47     DlpStateData infos;
48     FuzzedDataProvider fdp(data, size);
49     AbilityFuzzUtil::GetRandomConnectionData(fdp, info);
50     AbilityFuzzUtil::GetRandomDlpStateData(fdp, infos);
51     connectionObserverClientImpl->HandleExtensionConnected(info);
52     connectionObserverClientImpl->HandleExtensionDisconnected(info);
53     connectionObserverClientImpl->HandleExtensionSuspended(info);
54     connectionObserverClientImpl->HandleExtensionResumed(info);
55     connectionObserverClientImpl->HandleDlpAbilityOpened(infos);
56     return true;
57 }
58 }
59 
60 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63     /* Run your code on data */
64     OHOS::DoSomethingInterestingWithMyAPI(data, size);
65     return 0;
66 }
67 
68