diff --git a/bundle.json b/bundle.json index 313a10f..39d9c0c 100644 --- a/bundle.json +++ b/bundle.json @@ -50,7 +50,9 @@ } } ], - "test": [] + "test": [ + "///base/user_iam/face_auth/test/fuzztest:fuzztest" + ] } } } diff --git a/frameworks/face_auth/inc/face_auth_stub.h b/frameworks/face_auth/inc/face_auth_stub.h index 5c2fb58..96a1b25 100644 --- a/frameworks/face_auth/inc/face_auth_stub.h +++ b/frameworks/face_auth/inc/face_auth_stub.h @@ -30,8 +30,7 @@ class FaceAuthStub : public IRemoteStub, public NoCopyable { public: FaceAuthStub(); ~FaceAuthStub() override = default; - int32_t OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: using Handler = int32_t (FaceAuthStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000..c13b678 --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("fuzztest") { + testonly = true + deps = [ "face_auth_service_fuzzer:FaceAuthServiceFuzzTest" ] +} diff --git a/test/fuzztest/face_auth_service_fuzzer/BUILD.gn b/test/fuzztest/face_auth_service_fuzzer/BUILD.gn new file mode 100644 index 0000000..5f0103d --- /dev/null +++ b/test/fuzztest/face_auth_service_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/aafwk/standard/aafwk.gni") + +ohos_fuzztest("FaceAuthServiceFuzzTest") { + module_out_path = "useriam/face_auth" + fuzz_config_file = + "//base/user_iam/face_auth/test/fuzztest/face_auth_service_fuzzer" + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ + "//base/user_iam/face_auth/common/inc", + "//base/user_iam/user_auth/common/logs", + "//base/user_iam/user_auth/common/utils", + "//base/user_iam/face_auth/services/inc", + ] + + sources = [ "face_auth_service_fuzzer.cpp" ] + + deps = [ + "//base/user_iam/face_auth/frameworks/face_auth:faceauth_framework", + "//base/user_iam/face_auth/services:faceauthservice", + "//base/user_iam/user_auth/common:iam_test", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] + + if (ability_runtime_graphics) { + external_deps += [ "graphic_standard:surface" ] + } +} diff --git a/test/fuzztest/face_auth_service_fuzzer/corpus/init b/test/fuzztest/face_auth_service_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/face_auth_service_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.cpp b/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.cpp new file mode 100644 index 0000000..f049c72 --- /dev/null +++ b/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "face_auth_service_fuzzer.h" + +#include +#include + +#include "parcel.h" +#include "ibuffer_producer.h" + +#include "iam_logger.h" + +#include "face_auth_service.h" + +#define LOG_LABEL UserIAM::Common::LABEL_FACE_AUTH_SA + +#undef private + +using namespace std; +using namespace OHOS::UserIAM::Common; + +namespace OHOS { +namespace UserIAM { +namespace FaceAuth { +namespace { +class DummyBufferProducer : public IBufferProducer { +public: + ~DummyBufferProducer() = default; + GSError RequestBuffer( + const BufferRequestConfig &config, sptr &bedata, RequestBufferReturnValue &retval) + { + return GSERROR_OK; + } + + GSError CancelBuffer(int32_t sequence, const sptr &bedata) + { + return GSERROR_OK; + } + + GSError FlushBuffer( + int32_t sequence, const sptr &bedata, const sptr &fence, BufferFlushConfig &config) + { + return GSERROR_OK; + } + + GSError AttachBuffer(sptr &buffer) + { + return GSERROR_OK; + } + + GSError DetachBuffer(sptr &buffer) + { + return GSERROR_OK; + } + + uint32_t GetQueueSize() + { + return 0; + } + + GSError SetQueueSize(uint32_t queueSize) + { + return GSERROR_OK; + } + + GSError GetName(std::string &name) + { + return GSERROR_OK; + } + + uint64_t GetUniqueId() + { + return 0; + } + + GSError GetNameAndUniqueId(std::string &name, uint64_t &uniqueId) + { + return GSERROR_OK; + } + + int32_t GetDefaultWidth() + { + return 0; + } + + int32_t GetDefaultHeight() + { + return 0; + } + + uint32_t GetDefaultUsage() + { + return 0; + } + + GSError CleanCache() + { + return GSERROR_OK; + } + + GSError RegisterReleaseListener(OnReleaseFunc func) + { + return GSERROR_OK; + } + + GSError SetTransform(TransformType transform) + { + return GSERROR_OK; + } + + GSError IsSupportedAlloc(const std::vector &infos, std::vector &supporteds) + { + return GSERROR_OK; + } + + GSError Disconnect() + { + return GSERROR_OK; + } + + sptr AsObject() + { + return nullptr; + } +}; + +auto g_service = FaceAuthService::GetInstance(); + +void FuzzOnStart(Parcel &parcel) +{ + IAM_LOGI("begin"); + g_service->OnStart(); + IAM_LOGI("end"); +} + +void FuzzOnStop(Parcel &parcel) +{ + IAM_LOGI("begin"); + g_service->OnStop(); + IAM_LOGI("end"); +} + +void FuzzSetBufferProducer(Parcel &parcel) +{ + IAM_LOGI("begin"); + sptr bufferProducer = nullptr; + if (parcel.ReadBool()) { + bufferProducer = new (std::nothrow) DummyBufferProducer(); + } + g_service->SetBufferProducer(bufferProducer); + IAM_LOGI("end"); +} + +using FuzzFunc = decltype(FuzzOnStart); +FuzzFunc *g_fuzzFuncs[] = {FuzzOnStart, FuzzOnStop, FuzzSetBufferProducer}; + +void FaceAuthServiceFuzzTest(const uint8_t *data, size_t size) +{ + Parcel parcel; + parcel.WriteBuffer(data, size); + parcel.RewindRead(0); + uint32_t index = parcel.ReadUint32() % (sizeof(g_fuzzFuncs) / sizeof(FuzzFunc *)); + auto fuzzFunc = g_fuzzFuncs[index]; + fuzzFunc(parcel); + return; +} +} // namespace +} // namespace FaceAuth +} // namespace UserIAM +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserIAM::FaceAuth::FaceAuthServiceFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.h b/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.h new file mode 100644 index 0000000..eecd288 --- /dev/null +++ b/test/fuzztest/face_auth_service_fuzzer/face_auth_service_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FACE_AUTH_SERVICE_FUZZER_H +#define FACE_AUTH_SERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "FaceAuthServiceFuzzTest" + +#endif // FACE_AUTH_SERVICE_FUZZER_H diff --git a/test/fuzztest/face_auth_service_fuzzer/project.xml b/test/fuzztest/face_auth_service_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/face_auth_service_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +