mirror of
https://gitee.com/openharmony/notification_common_event_service
synced 2024-11-23 16:10:07 +00:00
IssueNo:https://gitee.com/openharmony/notification_common_event_service/issues/I5Z20W?from=project-issue
Description:ans覆盖率提升common_event01 Sig:SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: wujiqin <wujiqin5@huawei.com> Change-Id: I49ef06722a7b7cc86b32fe856f2d671ae33b397c
This commit is contained in:
parent
83645da898
commit
a5abbd312a
@ -18,8 +18,11 @@ group("fuzztest") {
|
||||
|
||||
deps = [
|
||||
"asynccommoneventresult_fuzzer:AsyncCommonEventResultFuzzTest",
|
||||
"commoneventproxy_fuzzer:CommonEventProxyFuzzTest",
|
||||
"commoneventpublishinfo_fuzzer:CommonEventPublishInfoFuzzTest",
|
||||
"commoneventstub_fuzzer:CommonEventStubFuzzTest",
|
||||
"dumpstate_fuzzer:DumpStateFuzzTest",
|
||||
"eventreceiveproxy_fuzzer:EventReceiveProxyFuzzTest",
|
||||
"getstickycommonevent_fuzzer:GetStickyCommonEventFuzzTest",
|
||||
"matchingskills_fuzzer:MatchingSkillsFuzzTest",
|
||||
"publishcommonevent_fuzzer:PublishCommonEventFuzzTest",
|
||||
|
52
test/fuzztest/commoneventproxy_fuzzer/BUILD.gn
Normal file
52
test/fuzztest/commoneventproxy_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,52 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//base/notification/common_event_service/event.gni")
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "common_event_service/services"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("CommonEventProxyFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//base/notification/common_event_service/test/fuzztest/commoneventproxy_fuzzer"
|
||||
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "commoneventproxy_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ces_core_path}:cesfwk_core",
|
||||
"${ces_native_path}:cesfwk_innerkits",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":CommonEventProxyFuzzTest" ]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 "common_event_proxy.h"
|
||||
#include "common_event_listener.h"
|
||||
#include "commoneventproxy_fuzzer.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace {
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
}
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
sptr<IRemoteObject> object = nullptr;
|
||||
EventFwk::CommonEventProxy commonEventProxy(object);
|
||||
commonEventProxy.UnsubscribeCommonEvent(object);
|
||||
std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber = nullptr;
|
||||
EventFwk::CommonEventListener commonEventListener(commonEventSubscriber);
|
||||
commonEventListener.Stop();
|
||||
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;
|
||||
}
|
||||
|
||||
char* ch = (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,29 @@
|
||||
/*
|
||||
* 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 TEST_FUZZTEST_COMMONEVENTPROXY_FUZZER_COMMONEVENTPROXY_FUZZER_H
|
||||
#define TEST_FUZZTEST_COMMONEVENTPROXY_FUZZER_COMMONEVENTPROXY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "commoneventproxy_fuzzer"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
uint32_t U32_AT(const uint8_t *ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
|
||||
}
|
||||
|
||||
#endif // TEST_FUZZTEST_COMMONEVENTPROXY_FUZZER_COMMONEVENTPROXY_FUZZER_H
|
13
test/fuzztest/commoneventproxy_fuzzer/corpus/init
Normal file
13
test/fuzztest/commoneventproxy_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
25
test/fuzztest/commoneventproxy_fuzzer/project.xml
Normal file
25
test/fuzztest/commoneventproxy_fuzzer/project.xml
Normal file
@ -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>
|
49
test/fuzztest/commoneventpublishinfo_fuzzer/BUILD.gn
Normal file
49
test/fuzztest/commoneventpublishinfo_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,49 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//base/notification/common_event_service/event.gni")
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "common_event_service/services"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("CommonEventPublishInfoFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//base/notification/common_event_service/test/fuzztest/commoneventpublishinfo_fuzzer"
|
||||
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "commoneventpublishinfo_fuzzer.cpp" ]
|
||||
|
||||
deps = [ "${ces_native_path}:cesfwk_innerkits" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":CommonEventPublishInfoFuzzTest" ]
|
||||
}
|
||||
###############################################################################
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 "commoneventpublishinfo_fuzzer.h"
|
||||
#include "securec.h"
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "common_event_publish_info.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
namespace OHOS {
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
Parcel parcel;
|
||||
EventFwk::CommonEventPublishInfo PublishInfo;
|
||||
EventFwk::CommonEventPublishInfo commonEventPublishInfo(PublishInfo);
|
||||
commonEventPublishInfo.ReadFromParcel(parcel);
|
||||
commonEventPublishInfo.Unmarshalling(parcel);
|
||||
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;
|
||||
}
|
||||
|
||||
char* ch = (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,29 @@
|
||||
/*
|
||||
* 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 TEST_FUZZTEST_COMMONENTPUBLISHINFO_FUZZER_COMMONENTPUBLISHINFO_FUZZER_H
|
||||
#define TEST_FUZZTEST_COMMONENTPUBLISHINFO_FUZZER_COMMONENTPUBLISHINFO_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "commoneventpublishinfo_fuzzer"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
uint32_t U32_AT(const uint8_t *ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
|
||||
}
|
||||
|
||||
#endif // TEST_FUZZTEST_COMMONENTPUBLISHINFO_FUZZER_COMMONENTPUBLISHINFO_FUZZER_H
|
13
test/fuzztest/commoneventpublishinfo_fuzzer/corpus/init
Normal file
13
test/fuzztest/commoneventpublishinfo_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
25
test/fuzztest/commoneventpublishinfo_fuzzer/project.xml
Normal file
25
test/fuzztest/commoneventpublishinfo_fuzzer/project.xml
Normal file
@ -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>
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "common_event_stub.h"
|
||||
#include "common_event_data.h"
|
||||
#include "commoneventstub_fuzzer.h"
|
||||
#include "securec.h"
|
||||
|
||||
@ -27,10 +28,14 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
std::string stringData(data);
|
||||
int32_t code = U32_AT(reinterpret_cast<const uint8_t*>(data));
|
||||
bool enabled = *data % ENABLE;
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
EventFwk::CommonEventStub commonEventStub;
|
||||
// test PublishCommonEvent function
|
||||
AAFwk::Want want;
|
||||
EventFwk::CommonEventData commonEventData;
|
||||
EventFwk::CommonEventData eventData(want, code, stringData);
|
||||
commonEventData.SetWant(want);
|
||||
commonEventData.SetCode(code);
|
||||
commonEventData.SetData(stringData);
|
||||
@ -62,6 +67,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
commonEventStub.Freeze(code);
|
||||
// test Unfreeze function
|
||||
commonEventStub.Unfreeze(code);
|
||||
commonEventStub.OnRemoteRequest(code, dataParcel, reply, option);
|
||||
// test UnfreezeAll function
|
||||
return commonEventStub.UnfreezeAll();
|
||||
}
|
||||
|
52
test/fuzztest/eventreceiveproxy_fuzzer/BUILD.gn
Normal file
52
test/fuzztest/eventreceiveproxy_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,52 @@
|
||||
# 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.
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//base/notification/common_event_service/event.gni")
|
||||
import("//build/config/features.gni")
|
||||
import("//build/test.gni")
|
||||
module_output_path = "common_event_service/services"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("EventReceiveProxyFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//base/notification/common_event_service/test/fuzztest/eventreceiveproxy_fuzzer"
|
||||
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [ "eventreceiveproxy_fuzzer.cpp" ]
|
||||
|
||||
deps = [
|
||||
"${ces_core_path}:cesfwk_core",
|
||||
"${ces_native_path}:cesfwk_innerkits",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":EventReceiveProxyFuzzTest" ]
|
||||
}
|
||||
###############################################################################
|
13
test/fuzztest/eventreceiveproxy_fuzzer/corpus/init
Normal file
13
test/fuzztest/eventreceiveproxy_fuzzer/corpus/init
Normal file
@ -0,0 +1,13 @@
|
||||
# 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,69 @@
|
||||
/*
|
||||
* 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 "eventreceiveproxy_fuzzer.h"
|
||||
#include "securec.h"
|
||||
#include "event_receive_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
} // namespace EventFwk
|
||||
namespace {
|
||||
constexpr size_t U32_AT_SIZE = 4;
|
||||
constexpr uint8_t ENABLE = 2;
|
||||
}
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
// make common event data
|
||||
EventFwk::CommonEventData commonEventData;
|
||||
bool enabled = *data % ENABLE;
|
||||
std::shared_ptr<EventFwk::EventReceiveProxy> result = std::make_shared<EventFwk::EventReceiveProxy>(nullptr);
|
||||
if (result != nullptr) {
|
||||
result->NotifyEvent(commonEventData, enabled, enabled);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
char* ch = (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,29 @@
|
||||
/*
|
||||
* 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 TEST_FUZZTEST_EVENTRECEIVEPROXY_FUZZER_EVENTRECEIVEPROXY_FUZZER_H
|
||||
#define TEST_FUZZTEST_EVENTRECEIVEPROXY_FUZZER_EVENTRECEIVEPROXY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "eventreceiveproxy_fuzzer"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
uint32_t U32_AT(const uint8_t *ptr)
|
||||
{
|
||||
// convert fuzz input data to an integer
|
||||
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
|
||||
}
|
||||
|
||||
#endif // TEST_FUZZTEST_EVENTRECEIVEPROXY_FUZZER_EVENTRECEIVEPROXY_FUZZER_H
|
25
test/fuzztest/eventreceiveproxy_fuzzer/project.xml
Normal file
25
test/fuzztest/eventreceiveproxy_fuzzer/project.xml
Normal file
@ -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>
|
@ -28,6 +28,8 @@ namespace {
|
||||
bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
{
|
||||
std::string stringData(data);
|
||||
size_t index = U32_AT(reinterpret_cast<const uint8_t*>(data));
|
||||
Parcel parcel;
|
||||
// test MatchingSkills class function
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
// test HasEntity function
|
||||
@ -56,6 +58,11 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
matchingSkills.MatchEntity(permissions);
|
||||
// test MatchScheme function
|
||||
matchingSkills.MatchScheme(stringData);
|
||||
matchingSkills.GetEntity(index);
|
||||
matchingSkills.GetEvent(index);
|
||||
matchingSkills.GetScheme(index);
|
||||
matchingSkills.ReadFromParcel(parcel);
|
||||
matchingSkills.Unmarshalling(parcel);
|
||||
// test Match function
|
||||
AAFwk::Want want;
|
||||
return matchingSkills.Match(want);
|
||||
|
@ -13,6 +13,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "common_event_subscribe_info.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
#include "subscribecommonevent_fuzzer.h"
|
||||
#include "securec.h"
|
||||
#include "common_event_manager.h"
|
||||
@ -39,6 +45,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
std::string stringData(data);
|
||||
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
Parcel parcel;
|
||||
matchingSkills.AddEvent(stringData);
|
||||
matchingSkills.AddEntity(stringData);
|
||||
matchingSkills.AddScheme(stringData);
|
||||
@ -48,6 +55,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
|
||||
EventFwk::CommonEventSubscribeInfo::ThreadMode(mode);
|
||||
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
int32_t priority = U32_AT(reinterpret_cast<const uint8_t*>(data));
|
||||
subscribeInfo.ReadFromParcel(parcel);
|
||||
subscribeInfo.Unmarshalling(parcel);
|
||||
subscribeInfo.SetPriority(priority);
|
||||
subscribeInfo.SetPermission(stringData);
|
||||
subscribeInfo.SetDeviceId(stringData);
|
||||
|
Loading…
Reference in New Issue
Block a user