• 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 "updateserverconfig_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 "fuzz_data.h"
23 #include "nativetoken_kit.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 {
UpdateServerConfigFuzzTest(const uint8_t * data,size_t size)31 bool UpdateServerConfigFuzzTest(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     std::string parameters = fuzzData.GenerateString();
40     DomainServerConfig config;
41 
42     result = DomainAccountClient::GetInstance().UpdateServerConfig(configId, parameters, config);
43     return result == ERR_OK;
44 }
45 }
46 
NativeTokenGet()47 void NativeTokenGet()
48 {
49     uint64_t tokenId;
50     const char **perms = new const char *[1];
51     perms[0] = "ohos.permission.MANAGE_DOMAIN_ACCOUNT_SERVER_CONFIGS";
52     NativeTokenInfoParams infoInstance = {
53         .dcapsNum = 0,
54         .permsNum = 1,
55         .aclsNum = 0,
56         .perms = perms,
57         .acls = nullptr,
58         .aplStr = "system_core",
59     };
60     infoInstance.processName = "RegisterInputer";
61     tokenId = GetAccessTokenId(&infoInstance);
62     SetSelfTokenID(tokenId);
63     AccessTokenKit::ReloadNativeTokenInfo();
64     delete[] perms;
65 }
66 
67 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)68 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
69 {
70     NativeTokenGet();
71     return 0;
72 }
73 
74 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)75 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
76 {
77     /* Run your code on data */
78     OHOS::UpdateServerConfigFuzzTest(data, size);
79     return 0;
80 }
81 
82