mirror of
https://github.com/openharmony/useriam_faceauth.git
synced 2026-07-18 08:14:33 -04:00
!140 增加 faceauth fuzz 测试
Merge pull request !140 from Tianshi Liu/faceauth_fuzz
This commit is contained in:
+3
-1
@@ -50,7 +50,9 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"test": []
|
||||
"test": [
|
||||
"///base/user_iam/face_auth/test/fuzztest:fuzztest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ class FaceAuthStub : public IRemoteStub<IFaceAuth>, 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);
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
@@ -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" ]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#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<BufferExtraData> &bedata, RequestBufferReturnValue &retval)
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError CancelBuffer(int32_t sequence, const sptr<BufferExtraData> &bedata)
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError FlushBuffer(
|
||||
int32_t sequence, const sptr<BufferExtraData> &bedata, const sptr<SyncFence> &fence, BufferFlushConfig &config)
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError AttachBuffer(sptr<SurfaceBuffer> &buffer)
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError DetachBuffer(sptr<SurfaceBuffer> &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<VerifyAllocInfo> &infos, std::vector<bool> &supporteds)
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
GSError Disconnect()
|
||||
{
|
||||
return GSERROR_OK;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> 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<IBufferProducer> 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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
||||
Reference in New Issue
Block a user