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