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 "setaccountpolicy_fuzzer.h"
17
18 #include <unistd.h>
19 #include "domain_account_client.h"
20 #include "fuzz_data.h"
21
22 using namespace std;
23 using namespace OHOS::AccountSA;
24
25 namespace OHOS {
26 namespace {
27 const int ENUM_MAX = 5;
28 const int32_t EDM_UID = 3057;
29 }
SetAccountPolicyFuzzTest(const uint8_t * data,size_t size)30 bool SetAccountPolicyFuzzTest(const uint8_t* data, size_t size)
31 {
32 bool result = false;
33 if ((data == nullptr) || (size == 0)) {
34 return false;
35 }
36 FuzzData fuzzData(data, size);
37 auto useEdmUid = fuzzData.GenerateBool();
38 if (useEdmUid) {
39 setuid(EDM_UID);
40 }
41 DomainAccountInfo info;
42 info.domain_ = fuzzData.GenerateString();
43 info.accountName_ = fuzzData.GenerateString();
44 info.accountId_ = fuzzData.GenerateString();
45 info.isAuthenticated = fuzzData.GenerateBool();
46 info.serverConfigId_ = fuzzData.GenerateString();
47 int typeNumber = fuzzData.GetData<int>() % ENUM_MAX;
48 info.status_ = static_cast<DomainAccountStatus>(typeNumber);
49 auto policy = fuzzData.GenerateString();
50 result = DomainAccountClient::GetInstance().SetAccountPolicy(info, policy);
51 return result == ERR_OK;
52 }
53 }
54
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
57 {
58 /* Run your code on data */
59 OHOS::SetAccountPolicyFuzzTest(data, size);
60 return 0;
61 }
62
63