• 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 "connectionobserverclientimplfourth_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::shared_ptr<ConnectionObserver> observer;
47     std::shared_ptr<ServiceProxyAdapter> proxy;
48     FuzzedDataProvider fdp(data, size);
49     connectionObserverClientImpl->RegisterObserver(observer);
50     connectionObserverClientImpl->UnregisterObserver(observer);
51     connectionObserverClientImpl->RegisterObserverToServiceLocked(proxy);
52     connectionObserverClientImpl->UnregisterFromServiceLocked(proxy);
53     connectionObserverClientImpl->AddObserversLocked(observer);
54     sptr<IRemoteObject> remoteObj;
55     proxy = std::make_shared<ServiceProxyAdapter>(remoteObj);
56     connectionObserverClientImpl->RegisterObserverToServiceLocked(proxy);
57     connectionObserverClientImpl->UnregisterFromServiceLocked(proxy);
58     return true;
59 }
60 }
61 
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
64 {
65     /* Run your code on data */
66     OHOS::DoSomethingInterestingWithMyAPI(data, size);
67     return 0;
68 }
69 
70