1 /*
2 * Copyright (c) 2024 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 "updateseccompenhancestub_fuzzer.h"
17
18 #include <string>
19 #include <thread>
20 #include <vector>
21
22 #include "accesstoken_fuzzdata.h"
23 #undef private
24 #include "errors.h"
25 #include "i_privacy_manager.h"
26 #include "on_permission_used_record_callback_stub.h"
27 #include "permission_used_request.h"
28 #include "permission_used_request_parcel.h"
29 #include "privacy_manager_service.h"
30
31 using namespace std;
32 using namespace OHOS::Security::AccessToken;
33
34 namespace OHOS {
UpdateSecCompEnhanceStubFuzzTest(const uint8_t * data,size_t size)35 bool UpdateSecCompEnhanceStubFuzzTest(const uint8_t* data, size_t size)
36 {
37 if ((data == nullptr) || (size == 0)) {
38 return false;
39 }
40
41 AccessTokenFuzzData fuzzData(data, size);
42
43 MessageParcel datas;
44 datas.WriteInterfaceToken(IPrivacyManager::GetDescriptor());
45 if (!datas.WriteInt32(fuzzData.GetData<int32_t>())) {
46 return false;
47 }
48
49 if (!datas.WriteUint32(fuzzData.GetData<uint32_t>())) {
50 return false;
51 }
52
53 uint32_t code = static_cast<uint32_t>(PrivacyInterfaceCode::UPDATE_SEC_COMP_ENHANCE);
54
55 MessageParcel reply;
56 MessageOption option;
57 DelayedSingleton<PrivacyManagerService>::GetInstance()->OnRemoteRequest(code, datas, reply, option);
58
59 return true;
60 }
61 } // namespace OHOS
62
63 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)64 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
65 {
66 /* Run your code on data */
67 OHOS::UpdateSecCompEnhanceStubFuzzTest(data, size);
68 return 0;
69 }
70