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 "deleteremotehaptokeninfostub_fuzzer.h"
17
18 #include "fuzzer/FuzzedDataProvider.h"
19 #include "hap_token_info_for_sync_parcel.h"
20 #include "i_token_sync_manager.h"
21 #include "token_sync_manager_service.h"
22
23 using namespace std;
24 using namespace OHOS::Security::AccessToken;
25
26 namespace OHOS {
UpdateRemoteHapTokenInfo()27 void UpdateRemoteHapTokenInfo()
28 {
29 MessageParcel data;
30 if (!data.WriteInterfaceToken(ITokenSyncManager::GetDescriptor())) {
31 return;
32 }
33 HapTokenInfoForSyncParcel tokenInfoParcel;
34
35 if (!data.WriteParcelable(&tokenInfoParcel)) {
36 return;
37 }
38
39 MessageParcel reply;
40 MessageOption option(MessageOption::TF_SYNC);
41 DelayedSingleton<TokenSyncManagerService>::GetInstance()->SendRequest(static_cast<uint32_t>(
42 TokenSyncInterfaceCode::UPDATE_REMOTE_HAP_TOKEN_INFO), data, reply, option);
43 }
44
DeleteRemoteHapTokenInfoStubFuzzTest(const uint8_t * data,size_t size)45 bool DeleteRemoteHapTokenInfoStubFuzzTest(const uint8_t* data, size_t size)
46 {
47 if ((data == nullptr) || (size == 0)) {
48 return false;
49 }
50
51 FuzzedDataProvider provider(data, size);
52 AccessTokenID tokenID = provider.ConsumeIntegral<AccessTokenID>();
53
54 UpdateRemoteHapTokenInfo();
55
56 MessageParcel datas;
57 if (!datas.WriteInterfaceToken(ITokenSyncManager::GetDescriptor())) {
58 return false;
59 }
60
61 if (!datas.WriteUint32(tokenID)) {
62 return false;
63 }
64
65 uint32_t code = static_cast<uint32_t>(
66 TokenSyncInterfaceCode::DELETE_REMOTE_HAP_TOKEN_INFO);
67
68 MessageParcel reply;
69 MessageOption option(MessageOption::TF_SYNC);
70
71 DelayedSingleton<TokenSyncManagerService>::GetInstance()->OnRemoteRequest(code, datas, reply, option);
72
73 return true;
74 }
75 } // namespace OHOS
76
77 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)78 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
79 {
80 /* Run your code on data */
81 OHOS::DeleteRemoteHapTokenInfoStubFuzzTest(data, size);
82 return 0;
83 }
84