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 #ifndef IS_SO_CROP_H
22 #include "strongauthmanager.h"
23
24 using namespace OHOS::ScreenLock;
25 #else
26 using namespace OHOS;
27 #endif // IS_SO_CROP_H
28
29 namespace OHOS {
30 constexpr size_t THRESHOLD = 10;
31 constexpr size_t LENGTH = 1;
32
FuzzScreenlockAuthManager(const uint8_t * rawData,size_t size)33 bool FuzzScreenlockAuthManager(const uint8_t *rawData, size_t size)
34 {
35 if (size < LENGTH) {
36 return true;
37 }
38
39 #ifndef IS_SO_CROP_H
40 auto authmanager = DelayedSingleton<StrongAuthManger>::GetInstance();
41 if (authmanager == nullptr) {
42 return false;
43 }
44
45 int32_t userId = 100;
46 authmanager->RegistUserAuthSuccessEventListener();
47 authmanager->StartStrongAuthTimer(userId);
48 authmanager->GetTimerId(userId);
49 authmanager->ResetStrongAuthTimer(userId);
50 authmanager->DestroyStrongAuthTimer(userId);
51 authmanager->DestroyAllStrongAuthTimer();
52 authmanager->UnRegistUserAuthSuccessEventListener();
53 #endif // IS_SO_CROP_H
54 return true;
55 }
56
57 } // namespace OHOS
58
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
61 {
62 if (size < OHOS::THRESHOLD) {
63 return 0;
64 }
65
66 /* Run your code on data */
67 OHOS::FuzzScreenlockAuthManager(data, size);
68 return 0;
69 }