• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "subscribeappaccount_fuzzer.h"
17 
18 #include "app_account_manager.h"
19 #include "app_account_subscribe_info.h"
20 #include "account_log_wrapper.h"
21 #include <string>
22 #include <vector>
23 
24 using namespace std;
25 using namespace OHOS::AccountSA;
26 class AppAccountSubscriberTest : public AppAccountSubscriber {
27 public:
AppAccountSubscriberTest(const AppAccountSubscribeInfo & subscribeInfo)28     explicit AppAccountSubscriberTest(const AppAccountSubscribeInfo &subscribeInfo)
29         : AppAccountSubscriber(subscribeInfo)
30     {
31         ACCOUNT_LOGI("enter");
32     }
33 
~AppAccountSubscriberTest()34     ~AppAccountSubscriberTest()
35     {}
36 
OnAccountsChanged(const std::vector<AppAccountInfo> & accounts)37     virtual void OnAccountsChanged(const std::vector<AppAccountInfo> &accounts)
38     {
39         ACCOUNT_LOGI("enter");
40     }
41 };
42 namespace OHOS {
SubscribeAppAccountFuzzTest(const uint8_t * data,size_t size)43     bool SubscribeAppAccountFuzzTest(const uint8_t* data, size_t size)
44     {
45         bool result = false;
46         if (size > 0) {
47             std::string testOwner(reinterpret_cast<const char*>(data), size);
48             std::vector<std::string> owners;
49             owners.emplace_back(testOwner);
50             AppAccountSubscribeInfo subscribeInfo(owners);
51             auto subscriberTestPtr = std::make_shared<AppAccountSubscriberTest>(subscribeInfo);
52             result = AppAccountManager::SubscribeAppAccount(subscriberTestPtr);
53         }
54         return result;
55     }
56 }
57 
58 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
60 {
61     /* Run your code on data */
62     OHOS::SubscribeAppAccountFuzzTest(data, size);
63     return 0;
64 }
65 
66