1 /*
2 * Copyright (c) 2022 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 "checkaccountlabels_fuzzer.h"
17
18 #include <string>
19 #include <vector>
20 #include "app_account_manager.h"
21 #include "app_account_common.h"
22 #include "account_log_wrapper.h"
23
24 using namespace std;
25 using namespace OHOS::AccountSA;
26
27 class MockAuthenticatorCallback : public OHOS::AccountSA::IAppAccountAuthenticatorCallback {
28 public:
OnResult(int32_t resultCode,const OHOS::AAFwk::Want & result)29 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result) override
30 {
31 return;
32 }
OnRequestRedirected(OHOS::AAFwk::Want & request)33 void OnRequestRedirected(OHOS::AAFwk::Want& request) override
34 {
35 return;
36 }
OnRequestContinued()37 void OnRequestContinued() override
38 {
39 return;
40 }
AsObject()41 OHOS::sptr<OHOS::IRemoteObject> AsObject() override
42 {
43 return nullptr;
44 }
45 };
46
47 namespace OHOS {
CheckAccountLabelsFuzzTest(const uint8_t * data,size_t size)48 bool CheckAccountLabelsFuzzTest(const uint8_t* data, size_t size)
49 {
50 bool result = false;
51 if (size > 0) {
52 std::string testName(reinterpret_cast<const char*>(data), size);
53 std::string testOwner(reinterpret_cast<const char*>(data), size);
54 std::string testValue(reinterpret_cast<const char*>(data), size);
55 std::vector<std::string> testLabels;
56 testLabels.emplace_back(testValue);
57 sptr<MockAuthenticatorCallback> callback = new (std::nothrow) MockAuthenticatorCallback();
58 result = AppAccountManager::CheckAccountLabels(testName, testOwner, testLabels, callback);
59 }
60 return result;
61 }
62 }
63
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67 /* Run your code on data */
68 OHOS::CheckAccountLabelsFuzzTest(data, size);
69 return 0;
70 }
71
72