• 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 "abilitydebugresponsestub_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21 #define private public
22 #define protected public
23 #include "ability_debug_response_stub.h"
24 #undef protected
25 #undef private
26 
27 using namespace OHOS::AppExecFwk;
28 
29 namespace OHOS {
30 namespace {
31     constexpr size_t U32_AT_SIZE = 4;
32 }
33 
34 const std::u16string IA_APP_FOREGROUND_STATE_OBSERVER_TOKEN = u"ohos.appexecfwk.AbilityDebugResponse";
35 
36 class AbilityDebugResponseStubFuzz : public AbilityDebugResponseStub {
37 public:
AbilityDebugResponseStubFuzz()38     explicit AbilityDebugResponseStubFuzz() {};
~AbilityDebugResponseStubFuzz()39     virtual ~AbilityDebugResponseStubFuzz() {};
40 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41     virtual int OnRemoteRequest(
42         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override{ return 0; };
43 
OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> & tokens)44     virtual void OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> &tokens) override{};
OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> & tokens)45     virtual void OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> &tokens) override{};
OnAbilitysAssertDebugChange(const std::vector<sptr<IRemoteObject>> & tokens,bool isAssertDebug)46     virtual void OnAbilitysAssertDebugChange(
47         const std::vector<sptr<IRemoteObject>> &tokens, bool isAssertDebug) override{};
48 };
49 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)50 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
51 {
52     FuzzedDataProvider fdp(data, size);
53     uint32_t code = fdp.ConsumeIntegralInRange<int32_t>(0, U32_AT_SIZE);
54     MessageParcel parcel;
55     parcel.WriteInterfaceToken(IA_APP_FOREGROUND_STATE_OBSERVER_TOKEN);
56     parcel.WriteBuffer(data, size);
57     parcel.RewindRead(0);
58     MessageParcel reply;
59     MessageOption option;
60     std::shared_ptr<AbilityDebugResponseStub> stub = std::make_shared<AbilityDebugResponseStubFuzz>();
61     stub->OnRemoteRequest(code, parcel, reply, option);
62     return true;
63 }
64 }
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     /* Run your code on data */
70 
71     OHOS::DoSomethingInterestingWithMyAPI(data, size);
72     return 0;
73 }