• 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 "gettokenidbyuseridstub_fuzzer.h"
17 
18 #undef private
19 #include "accesstoken_manager_service.h"
20 #include "fuzzer/FuzzedDataProvider.h"
21 #include "iaccess_token_manager.h"
22 
23 using namespace std;
24 using namespace OHOS::Security::AccessToken;
25 
26 namespace OHOS {
GetTokenIDByUserIDStubFuzzTest(const uint8_t * data,size_t size)27     bool GetTokenIDByUserIDStubFuzzTest(const uint8_t* data, size_t size)
28     {
29         if ((data == nullptr) || (size == 0)) {
30             return false;
31         }
32 
33         FuzzedDataProvider provider(data, size);
34 
35         MessageParcel datas;
36         datas.WriteInterfaceToken(IAccessTokenManager::GetDescriptor());
37 
38         int32_t userID = provider.ConsumeIntegral<int32_t>();
39         if (!datas.WriteInt32(userID)) {
40             return false;
41         }
42 
43         uint32_t code = static_cast<uint32_t>(
44             IAccessTokenManagerIpcCode::COMMAND_GET_TOKEN_I_D_BY_USER_I_D);
45 
46         MessageParcel reply;
47         MessageOption option;
48         DelayedSingleton<AccessTokenManagerService>::GetInstance()->OnRemoteRequest(code, datas, reply, option);
49 
50         return true;
51     }
52 } // namespace OHOS
53 
54 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)55 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
56 {
57     /* Run your code on data */
58     OHOS::GetTokenIDByUserIDStubFuzzTest(data, size);
59     return 0;
60 }
61