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 "connectionobserverclientimplfifth_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 wptr<IRemoteObject> remote;
48 FuzzedDataProvider fdp(data, size);
49 connectionObserverClientImpl->RemoveObserversLocked(observer);
50 connectionObserverClientImpl->GetServiceProxy();
51 connectionObserverClientImpl->ConnectLocked();
52 connectionObserverClientImpl->HandleRemoteDied(remote);
53 connectionObserverClientImpl->ResetProxy(remote);
54 connectionObserverClientImpl->ResetStatus();
55 connectionObserverClientImpl->NotifyServiceDiedToObservers();
56 connectionObserverClientImpl->GetObservers();
57 auto deathRecipient = new (std::nothrow) AbilityRuntime::ConnectionObserverClientImpl::ServiceDeathRecipient(
58 connectionObserverClientImpl);
59 deathRecipient->OnRemoteDied(remote);
60 return true;
61 }
62 }
63
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67 /* Run your code on data */
68 OHOS::DoSomethingInterestingWithMyAPI(data, size);
69 return 0;
70 }
71
72