1 /*
2  * Copyright (c) 2021-2022 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  * miscservices under the License is miscservices 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 "screenlockauthmanager_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <string_ex.h>
21 #include "strongauthmanager.h"
22 
23 using namespace OHOS::ScreenLock;
24 
25 namespace OHOS {
26 constexpr size_t THRESHOLD = 10;
27 constexpr size_t LENGTH = 1;
28 
FuzzScreenlockAuthManager(const uint8_t * rawData,size_t size)29 bool FuzzScreenlockAuthManager(const uint8_t *rawData, size_t size)
30 {
31     if (size < LENGTH) {
32         return true;
33     }
34 
35     auto authmanager = DelayedSingleton<StrongAuthManger>::GetInstance();
36     if (authmanager == nullptr) {
37         return false;
38     }
39 
40     int32_t userId = 100;
41     authmanager->RegistUserAuthSuccessEventListener();
42     authmanager->StartStrongAuthTimer(userId);
43     authmanager->GetTimerId(userId);
44     authmanager->ResetStrongAuthTimer(userId);
45     authmanager->DestroyStrongAuthTimer(userId);
46     authmanager->DestroyAllStrongAuthTimer();
47     authmanager->UnRegistUserAuthSuccessEventListener();
48     return true;
49 }
50 
51 } // namespace OHOS
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
55 {
56     if (size < OHOS::THRESHOLD) {
57         return 0;
58     }
59 
60     /* Run your code on data */
61     OHOS::FuzzScreenlockAuthManager(data, size);
62     return 0;
63 }