1 /*
2 * Copyright (c) 2024-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 "getaccountserverconfig_fuzzer.h"
17
18 #include <string>
19 #include "access_token.h"
20 #include "access_token_error.h"
21 #include "accesstoken_kit.h"
22 #include "account_log_wrapper.h"
23 #include "domain_account_client.h"
24 #include "fuzz_data.h"
25 #include "nativetoken_kit.h"
26 #include "token_setproc.h"
27
28 using namespace std;
29 using namespace OHOS::AccountSA;
30 using namespace OHOS::Security::AccessToken;
31
32 namespace {
33 constexpr int32_t PERMISSION_COUNT_NUM = 2;
34 constexpr int32_t FIRST_PARAM_INDEX = 0;
35 constexpr int32_t SECOND_PARAM_INDEX = 1;
36 }
37 namespace OHOS {
38
GetAccountServerConfigFuzzTest(const uint8_t * data,size_t size)39 bool GetAccountServerConfigFuzzTest(const uint8_t* data, size_t size)
40 {
41 if ((data == nullptr) || (size == 0)) {
42 return false;
43 }
44 FuzzData fuzzData(data, size);
45 DomainAccountInfo info;
46 DomainServerConfig config;
47 std::string accoutId(fuzzData.GenerateString());
48 std::string accountName(fuzzData.GenerateString());
49 std::string domain(fuzzData.GenerateString());
50 std::string serverConfigId(fuzzData.GenerateString());
51 info.accountId_ = accoutId;
52 info.accountName_ = accountName;
53 info.domain_ = domain;
54 info.serverConfigId_ = serverConfigId;
55 DomainAccountClient::GetInstance().GetAccountServerConfig(info, config);
56 return true;
57 }
58 }
59
NativeTokenGet()60 void NativeTokenGet()
61 {
62 uint64_t tokenId;
63 const char **perms = new const char *[PERMISSION_COUNT_NUM];
64 perms[FIRST_PARAM_INDEX] = "ohos.permission.MANAGE_LOCAL_ACCOUNTS";
65 perms[SECOND_PARAM_INDEX] = "ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS";
66 NativeTokenInfoParams infoInstance = {
67 .dcapsNum = 0,
68 .permsNum = PERMISSION_COUNT_NUM,
69 .aclsNum = 0,
70 .perms = perms,
71 .acls = nullptr,
72 .aplStr = "system_core",
73 };
74 infoInstance.processName = "RegisterInputer";
75 tokenId = GetAccessTokenId(&infoInstance);
76 SetSelfTokenID(tokenId);
77 AccessTokenKit::ReloadNativeTokenInfo();
78 delete[] perms;
79 }
80
81 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)82 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
83 {
84 NativeTokenGet();
85 return 0;
86 }
87
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
90 {
91 /* Run your code on data */
92 OHOS::GetAccountServerConfigFuzzTest(data, size);
93 return 0;
94 }
95
96