• 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 "data_collect_manager_callback_proxy_fuzzer.h"
17 
18 #include <string>
19 #include <fuzzer/FuzzedDataProvider.h>
20 #include "securec.h"
21 #include <string_ex.h>
22 
23 #define private public
24 #define protected public
25 #include "event_define.h"
26 #include "acquire_data_subscribe_manager.h"
27 #include "acquire_data_callback_proxy.h"
28 #include "data_collect_manager_callback_proxy.h"
29 #include "data_collect_manager_service.h"
30 #include "data_collect_manager_idl_stub.h"
31 #include "security_event_query_callback_proxy.h"
32 #include "database_helper.h"
33 #include "database_manager.h"
34 #include "database.h"
35 #include "risk_event_rdb_helper.h"
36 #include "store_define.h"
37 #undef private
38 #undef prtected
39 
40 using namespace OHOS::Security::SecurityGuard;
41 namespace {
42     constexpr int MAX_STRING_SIZE = 1024;
43 }
44 namespace OHOS {
45 class MockRemoteObject final : public IRemoteObject {
46 public:
MockRemoteObject()47     MockRemoteObject() : IRemoteObject(u"")
48     {
49     }
GetObjectRefCount()50     int32_t GetObjectRefCount() { return 0; };
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return 0; };
AddDeathRecipient(const sptr<DeathRecipient> & recipient)52     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; };
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)53     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; };
Dump(int fd,const std::vector<std::u16string> & args)54     int Dump(int fd, const std::vector<std::u16string> &args) { return 0; };
55 };
56 
DataCollectManagerCallbackProxyFuzzTest(const uint8_t * data,size_t size)57 bool DataCollectManagerCallbackProxyFuzzTest(const uint8_t* data, size_t size)
58 {
59     FuzzedDataProvider fdp(data, size);
60     uint32_t status = fdp.ConsumeIntegral<uint32_t>();
61     std::string string = fdp.ConsumeRandomLengthString(MAX_STRING_SIZE);
62     sptr<IRemoteObject> obj(new (std::nothrow) MockRemoteObject());
63     DataCollectManagerCallbackProxy proxy{obj};
64     proxy.ResponseRiskData(string, string, status);
65     return true;
66 }
67 }  // namespace OHOS
68 
69 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)70 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
71 {
72     /* Run your code on date */
73     OHOS::DataCollectManagerCallbackProxyFuzzTest(data, size);
74     return 0;
75 }