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 #define private public
17 #include "bmskeyeventmgr_fuzzer.h"
18
19 #include "bms_key_event_mgr.h"
20 #include "securec.h"
21
22 using namespace OHOS::AppExecFwk;
23 namespace OHOS {
24 constexpr size_t U32_AT_SIZE = 4;
25
DoSomethingInterestingWithMyAPI(const char * data,size_t size)26 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
27 {
28 BmsKeyEventMgr::ProcessMainBundleStatusFinally();
29 BmsKeyEventMgr::ProcessMainBundleInstallFailed(std::string(data, size), 0);
30 return true;
31 }
32 } // namespace OHOS
33
34 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)35 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
36 {
37 /* Run your code on data */
38 if (data == nullptr) {
39 return 0;
40 }
41
42 if (size < OHOS::U32_AT_SIZE) {
43 return 0;
44 }
45
46 char* ch = static_cast<char*>(malloc(size + 1));
47 if (ch == nullptr) {
48 return 0;
49 }
50
51 (void)memset_s(ch, size + 1, 0x00, size + 1);
52 if (memcpy_s(ch, size, data, size) != EOK) {
53 free(ch);
54 ch = nullptr;
55 return 0;
56 }
57 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
58 free(ch);
59 ch = nullptr;
60 return 0;
61 }