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 "getserverconfig_fuzzer.h"
17
18 #include "access_token.h"
19 #include "access_token_error.h"
20 #include "accesstoken_kit.h"
21 #include "domain_account_client.h"
22 #include "nativetoken_kit.h"
23 #include "fuzz_data.h"
24 #include "token_setproc.h"
25
26 using namespace std;
27 using namespace OHOS::AccountSA;
28 using namespace OHOS::Security::AccessToken;
29
30 namespace OHOS {
GetServerConfigFuzzTest(const uint8_t * data,size_t size)31 bool GetServerConfigFuzzTest(const uint8_t* data, size_t size)
32 {
33 bool result = false;
34 if ((data == nullptr) || (size == 0)) {
35 return false;
36 }
37 FuzzData fuzzData(data, size);
38 std::string configId = fuzzData.GenerateString();
39 DomainServerConfig config;
40 result = DomainAccountClient::GetInstance().GetServerConfig(configId, config);
41 return result == ERR_OK;
42 }
43 }
44
NativeTokenGet()45 void NativeTokenGet()
46 {
47 uint64_t tokenId;
48 const char **perms = new const char *[1];
49 perms[0] = "ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS";
50 NativeTokenInfoParams infoInstance = {
51 .dcapsNum = 0,
52 .permsNum = 1,
53 .aclsNum = 0,
54 .perms = perms,
55 .acls = nullptr,
56 .aplStr = "system_core",
57 };
58 infoInstance.processName = "RegisterInputer";
59 tokenId = GetAccessTokenId(&infoInstance);
60 SetSelfTokenID(tokenId);
61 AccessTokenKit::ReloadNativeTokenInfo();
62 delete[] perms;
63 }
64
65 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)66 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
67 {
68 NativeTokenGet();
69 return 0;
70 }
71
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75 /* Run your code on data */
76 OHOS::GetServerConfigFuzzTest(data, size);
77 return 0;
78 }
79
80