• 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 "deluserstub_fuzzer.h"
17 #include <string>
18 #include <vector>
19 #include "account_log_wrapper.h"
20 #include "account_iam_service.h"
21 #include "account_iam_client.h"
22 #include "account_iam_callback_service.h"
23 #include "iaccount_iam.h"
24 
25 using namespace std;
26 using namespace OHOS::AccountSA;
27 namespace OHOS {
28 const std::u16string IAMACCOUNT_TOKEN = u"ohos.accountfwk.IAccountIAM";
29 
30 class MockIDMCallback : public OHOS::AccountSA::IDMCallback {
31 public:
~MockIDMCallback()32     virtual ~MockIDMCallback() {}
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)33     void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override
34     {
35         return;
36     }
OnResult(int32_t result,const Attributes & extraInfo)37     void OnResult(int32_t result, const Attributes &extraInfo) override
38     {
39         return;
40     }
41 };
42 
DelUserStubFuzzTest(const uint8_t * data,size_t size)43 bool DelUserStubFuzzTest(const uint8_t *data, size_t size)
44 {
45     if ((data == nullptr) || (size == 0)) {
46         return false;
47     }
48 
49     int32_t userId = static_cast<int32_t>(size);
50     std::vector<uint8_t> authToken = {static_cast<uint8_t>(size)};
51     std::shared_ptr<IDMCallback> ptr = make_shared<MockIDMCallback>();
52     sptr<IIDMCallback> callback = new (std::nothrow) IDMCallbackService(userId, ptr);
53 
54     MessageParcel dataTemp;
55     if (!dataTemp.WriteInterfaceToken(IAMACCOUNT_TOKEN)) {
56         return false;
57     }
58 
59     if (!dataTemp.WriteInt32(userId)) {
60         return false;
61     }
62 
63     if (!dataTemp.WriteUInt8Vector(authToken)) {
64         return false;
65     }
66 
67     if (!dataTemp.WriteRemoteObject(callback->AsObject())) {
68         return false;
69     }
70 
71     MessageParcel reply;
72     MessageOption option;
73     uint32_t code = static_cast<uint32_t>(AccountIAMInterfaceCode::DEL_USER);
74     auto iamAccountManagerService = std::make_shared<AccountIAMService>();
75     iamAccountManagerService->OnRemoteRequest(code, dataTemp, reply, option);
76 
77     return true;
78 }
79 } // namespace OHOS
80 
81 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)82 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
83 {
84     /* Run your code on data */
85     OHOS::DelUserStubFuzzTest(data, size);
86     return 0;
87 }
88