mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-23 07:09:53 +00:00
fuzz新增:VerifyManagerHostFuzzTest
Signed-off-by: Lotol <linxiangzhi@huawei.com> Change-Id: Ia616a99a4d1eac2f3c2823c22e9fe0da1729f96c
This commit is contained in:
parent
9bb2a288dc
commit
0ec853802d
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2024 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
|
||||
@ -43,6 +43,7 @@ group("fuzztest") {
|
||||
"fuzztest_application/cleanbundledatafiles_fuzzer:CleanBundleDataFilesFuzzTest",
|
||||
"fuzztest_application/cleancachecallbackproxy_fuzzer:CleanCacheCallbackProxyFuzzTest",
|
||||
"fuzztest_application/defaultapphost_fuzzer:DefaultAppHostFuzzTest",
|
||||
"fuzztest_application/verifymanagerhost_fuzzer:VerifyManagerHostFuzzTest",
|
||||
"fuzztest_information/abilityinfofromjson_fuzzer:AbilityInfoFromJsonFuzzTest",
|
||||
"fuzztest_information/abilityinfomarshalling_fuzzer:AbilityInfoMarshallingFuzzTest",
|
||||
"fuzztest_information/abilityinfounmarshalling_fuzzer:AbilityInfoUnmarshallingFuzzTest",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-2024 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
|
||||
@ -25,7 +25,7 @@ using namespace OHOS::AppExecFwk;
|
||||
namespace OHOS {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t MESSAGE_SIZE = 18;
|
||||
constexpr size_t MESSAGE_SIZE = 21;
|
||||
constexpr size_t DCAMERA_SHIFT_24 = 24;
|
||||
constexpr size_t DCAMERA_SHIFT_16 = 16;
|
||||
constexpr size_t DCAMERA_SHIFT_8 = 8;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-2024 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
|
||||
@ -25,7 +25,7 @@ using namespace OHOS::AppExecFwk;
|
||||
namespace OHOS {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t MESSAGE_SIZE = 117;
|
||||
constexpr size_t MESSAGE_SIZE = 131;
|
||||
constexpr size_t DCAMERA_SHIFT_24 = 24;
|
||||
constexpr size_t DCAMERA_SHIFT_16 = 16;
|
||||
constexpr size_t DCAMERA_SHIFT_8 = 8;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-2024 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
|
||||
@ -25,7 +25,7 @@ using namespace OHOS::AppExecFwk;
|
||||
namespace OHOS {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t MESSAGE_SIZE = 4;
|
||||
constexpr size_t MESSAGE_SIZE = 5;
|
||||
constexpr size_t DCAMERA_SHIFT_24 = 24;
|
||||
constexpr size_t DCAMERA_SHIFT_16 = 16;
|
||||
constexpr size_t DCAMERA_SHIFT_8 = 8;
|
||||
|
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//build/config/features.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
import("../../../../appexecfwk.gni")
|
||||
module_output_path = fuzz_test_path
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("VerifyManagerHostFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file =
|
||||
"../../../fuzztest/fuzztest_application/verifymanagerhost_fuzzer"
|
||||
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "verifymanagerhost_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${base_path}:appexecfwk_base",
|
||||
"${common_path}:libappexecfwk_common",
|
||||
"${core_path}:appexecfwk_core",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2024 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,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2024 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>
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "verifymanagerhost_fuzzer.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "verify_manager_host.h"
|
||||
#include "securec.h"
|
||||
|
||||
using namespace OHOS::AppExecFwk;
|
||||
namespace OHOS {
|
||||
constexpr size_t FOO_MAX_LEN = 1024;
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr size_t MESSAGE_SIZE = 3;
|
||||
constexpr size_t DCAMERA_SHIFT_24 = 24;
|
||||
constexpr size_t DCAMERA_SHIFT_16 = 16;
|
||||
constexpr size_t DCAMERA_SHIFT_8 = 8;
|
||||
|
||||
uint32_t GetU32Data(const char* ptr)
|
||||
{
|
||||
return (ptr[0] << DCAMERA_SHIFT_24) | (ptr[1] << DCAMERA_SHIFT_16) | (ptr[2] << DCAMERA_SHIFT_8) | (ptr[3]);
|
||||
}
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
uint32_t code = (GetU32Data(data) % MESSAGE_SIZE);
|
||||
MessageParcel datas;
|
||||
std::u16string descriptor = VerifyManagerHost::GetDescriptor();
|
||||
datas.WriteInterfaceToken(descriptor);
|
||||
datas.WriteBuffer(data, size);
|
||||
datas.RewindRead(0);
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
VerifyManagerHost verifyManagerHost;
|
||||
verifyManagerHost.OnRemoteRequest(code, datas, reply, option);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
if (data == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size < OHOS::U32_AT_SIZE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Validate the length of size */
|
||||
if (size > OHOS::FOO_MAX_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* ch = static_cast<char*>(malloc(size + 1));
|
||||
if (ch == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)memset_s(ch, size + 1, 0x00, size + 1);
|
||||
if (memcpy_s(ch, size, data, size) != EOK) {
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
||||
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
|
||||
free(ch);
|
||||
ch = nullptr;
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 TEST_FUZZTEST_VERIFYMANAGERHOST_FUZZER_H
|
||||
#define TEST_FUZZTEST_VERIFYMANAGERHOST_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "verifymanagerhost_fuzzer"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user