• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "cmdqueryohosaccountinfostub_fuzzer.h"
17 
18 #include <string>
19 #include <vector>
20 #include "src/callbacks.h"
21 
22 #define private public
23 #include "account_mgr_service.h"
24 #undef private
25 #include "iaccount.h"
26 
27 using namespace std;
28 using namespace OHOS::AccountSA;
29 
30 namespace OHOS {
31 namespace {
32 const std::u16string ACCOUNT_TOKEN = u"ohos.accountfwk.IAccount";
33 static pthread_once_t g_fcOnce = PTHREAD_ONCE_INIT;
34 }
35 
SelinuxLog(int logLevel,const char * fmt,...)36 static int SelinuxLog(int logLevel, const char *fmt, ...)
37 {
38     (void)logLevel;
39     (void)fmt;
40     return 0;
41 }
42 
SelinuxSetCallback()43 static void SelinuxSetCallback()
44 {
45     union selinux_callback cb;
46     cb.func_log = SelinuxLog;
47     selinux_set_callback(SELINUX_CB_LOG, cb);
48 }
49 
CmdQueryOhosAccountInfoStubFuzzTest(const uint8_t * data,size_t size)50 bool CmdQueryOhosAccountInfoStubFuzzTest(const uint8_t* data, size_t size)
51 {
52     __selinux_once(g_fcOnce, SelinuxSetCallback);
53     if ((data == nullptr) || (size == 0)) {
54         return false;
55     }
56     MessageParcel dataTemp;
57     if (!dataTemp.WriteInterfaceToken(ACCOUNT_TOKEN)) {
58         return false;
59     }
60     MessageParcel reply;
61     MessageOption option;
62     uint32_t code = static_cast<uint32_t>(AccountMgrInterfaceCode::QUERY_OHOS_ACCOUNT_INFO);
63     DelayedRefSingleton<AccountMgrService>::GetInstance().state_ = ServiceRunningState::STATE_RUNNING;
64     DelayedRefSingleton<AccountMgrService>::GetInstance().OnRemoteRequest(code, dataTemp, reply, option);
65 
66     return true;
67 }
68 }
69 
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72 {
73     /* Run your code on data */
74     OHOS::CmdQueryOhosAccountInfoStubFuzzTest(data, size);
75     return 0;
76 }
77 
78