1 /*
2 * Copyright (c) 2023 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 "face_auth_stub_fuzzer.h"
17
18 #include <cinttypes>
19 #include <cstddef>
20 #include <cstdint>
21
22 #include "parcel.h"
23
24 #include "face_auth_service.h"
25 #include "iam_fuzz_test.h"
26 #include "iam_logger.h"
27
28 #define LOG_TAG "FACE_AUTH_SA"
29
30 using namespace std;
31
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 namespace {
36 constexpr uint32_t FACE_AUTH_CODE_MIN = 1;
37 constexpr uint32_t FACE_AUTH_CODE_MAX = 2;
38 const std::u16string FACE_AUTH_INTERFACE_TOKEN = u"ohos.faceauth.IFaceAuth";
39
FaceAuthStubFuzzTest(const uint8_t * rawData,size_t size)40 bool FaceAuthStubFuzzTest(const uint8_t *rawData, size_t size)
41 {
42 IAM_LOGI("start");
43 if (rawData == nullptr) {
44 return false;
45 }
46 auto faceAuthservice = FaceAuth::FaceAuthService::GetInstance();
47 for (uint32_t code = FACE_AUTH_CODE_MIN; code < FACE_AUTH_CODE_MAX; code++) {
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption optionSync = MessageOption::TF_SYNC;
51 MessageOption optionAsync = MessageOption::TF_ASYNC;
52 // Sync
53 data.WriteInterfaceToken(FACE_AUTH_INTERFACE_TOKEN);
54 data.WriteBuffer(rawData, size);
55 data.RewindRead(0);
56 (void)faceAuthservice->OnRemoteRequest(code, data, reply, optionSync);
57 // Async
58 data.WriteInterfaceToken(FACE_AUTH_INTERFACE_TOKEN);
59 data.WriteBuffer(rawData, size);
60 data.RewindRead(0);
61 (void)faceAuthservice->OnRemoteRequest(code, data, reply, optionAsync);
62 }
63 return true;
64 }
65 } // namespace
66 } // namespace UserAuth
67 } // namespace UserIam
68 } // namespace OHOS
69
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
72 {
73 /* Run your code on data */
74 OHOS::UserIam::UserAuth::FaceAuthStubFuzzTest(data, size);
75 return 0;
76 }
77