• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "osaccountstatereplycallbackstub_fuzzer.h"
17 #include "accountmgr_service_ipc_interface_code.h"
18 #include "fuzz_data.h"
19 #include "os_account_state_reply_callback_stub.h"
20 
21 using namespace std;
22 using namespace OHOS::AccountSA;
23 
24 namespace OHOS {
25 const std::u16string DESCRIPTOR = u"ohos.accountfwk.IOsAccountStateReplyCallback";
26 
OsAccountStateReplyCallbackStubFuzzTest(const uint8_t * data,size_t size)27 bool OsAccountStateReplyCallbackStubFuzzTest(const uint8_t *data, size_t size)
28 {
29     if ((data == nullptr) || (size == 0)) {
30         return false;
31     }
32     FuzzData fuzzData(data, size);
33     MessageParcel message;
34     message.WriteInterfaceToken(DESCRIPTOR);
35     MessageParcel reply;
36     MessageOption option;
37     auto cvPtr = std::make_shared<std::condition_variable>();
38     auto safeQueue = std::make_shared<SafeQueue<uint8_t>>();
39     auto replyCallbackStub = std::make_shared<OsAccountStateReplyCallbackStub>(fuzzData.GetData<int32_t>(),
40         static_cast<OsAccountState>(fuzzData.GetData<int32_t>()), cvPtr, safeQueue, fuzzData.GetData<int32_t>());
41     replyCallbackStub->OnRemoteRequest(
42         static_cast<int32_t>(StateReplyCallbackInterfaceCode::ON_COMPLETE), message, reply, option);
43     return true;
44 }
45 } // namespace OHOS
46 
47 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49 {
50     /* Run your code on data */
51     OHOS::OsAccountStateReplyCallbackStubFuzzTest(data, size);
52     return 0;
53 }
54