1 /*
2 * Copyright (c) 2023-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 "unregisterpermactivestatuscallbackstub_fuzzer.h"
17
18 #include <string>
19 #include <thread>
20 #include <vector>
21
22 #undef private
23 #include "fuzzer/FuzzedDataProvider.h"
24 #include "iprivacy_manager.h"
25 #include "perm_active_status_change_callback.h"
26 #include "perm_active_status_customized_cbk.h"
27 #include "privacy_manager_service.h"
28
29 using namespace std;
30 using namespace OHOS::Security::AccessToken;
31
32 class RegisterActiveFuzzTest : public PermActiveStatusCustomizedCbk {
33 public:
RegisterActiveFuzzTest(const std::vector<std::string> & permList)34 explicit RegisterActiveFuzzTest(const std::vector<std::string> &permList)
35 : PermActiveStatusCustomizedCbk(permList)
36 {}
37
~RegisterActiveFuzzTest()38 ~RegisterActiveFuzzTest()
39 {}
40
ActiveStatusChangeCallback(ActiveChangeResponse & result)41 virtual void ActiveStatusChangeCallback(ActiveChangeResponse& result)
42 {
43 type_ = result.type;
44 return;
45 }
46
47 ActiveChangeType type_ = PERM_INACTIVE;
48 };
49
50 namespace OHOS {
UnRegisterPermActiveStatusCallbackStubFuzzTest(const uint8_t * data,size_t size)51 bool UnRegisterPermActiveStatusCallbackStubFuzzTest(const uint8_t* data, size_t size)
52 {
53 if ((data == nullptr) || (size == 0)) {
54 return false;
55 }
56
57 FuzzedDataProvider provider(data, size);
58
59 MessageParcel datas;
60 datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor());
61
62 std::vector<std::string> permList = {provider.ConsumeRandomLengthString()};
63 auto callback = std::make_shared<RegisterActiveFuzzTest>(permList);
64 callback->type_ = PERM_INACTIVE;
65
66 sptr<PermActiveStatusChangeCallback> callbackWrap = nullptr;
67 callbackWrap = new (std::nothrow) PermActiveStatusChangeCallback(callback);
68 if (!datas.WriteRemoteObject(callbackWrap->AsObject())) {
69 return false;
70 }
71
72 uint32_t code = static_cast<uint32_t>(IPrivacyManagerIpcCode::COMMAND_UN_REGISTER_PERM_ACTIVE_STATUS_CALLBACK);
73
74 MessageParcel reply;
75 MessageOption option;
76 DelayedSingleton<PrivacyManagerService>::GetInstance()->OnRemoteRequest(code, datas, reply, option);
77
78 return true;
79 }
80 } // namespace OHOS
81
82 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)83 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
84 {
85 /* Run your code on data */
86 OHOS::UnRegisterPermActiveStatusCallbackStubFuzzTest(data, size);
87 return 0;
88 }
89