From 0aefa8367a42513e0e707b948a441979af077a3c Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 3 Sep 2024 17:05:59 +0800 Subject: [PATCH 1/2] Code branch difference modification Signed-off-by: cff-gite Change-Id: I46cc93e5fc78161e6c58db16f4f8b61d84cde95a --- frameworks/js/napi/BUILD.gn | 12 +- frameworks/native/BUILD.gn | 6 +- interfaces/inner_api/sensor_agent_type.h | 2 +- .../adapter/src/sensor_event_callback.cpp | 10 +- .../interfaces/sensoragent_fuzzer/BUILD.gn | 9 +- .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 91 ++++----------- test/fuzztest/services/BUILD.gn | 11 -- .../createsocketchannel_fuzzer/BUILD.gn | 74 ------------ .../createsocketchannel_fuzzer/corpus/init | 14 --- .../createsocketchannel_fuzzer.cpp | 106 ----------------- .../createsocketchannel_fuzzer.h | 22 ---- .../createsocketchannel_fuzzer/project.xml | 25 ---- .../destroysensorchannel_fuzzer/BUILD.gn | 73 ------------ .../destroysensorchannel_fuzzer/corpus/init | 14 --- .../destroysensorchannel_fuzzer.cpp | 104 ----------------- .../destroysensorchannel_fuzzer.h | 22 ---- .../destroysensorchannel_fuzzer/project.xml | 25 ---- .../service/getactiveinfolist_fuzzer/BUILD.gn | 74 ------------ .../getactiveinfolist_fuzzer/corpus/init | 14 --- .../getactiveinfolist_fuzzer.cpp | 105 ----------------- .../getactiveinfolist_fuzzer.h | 22 ---- .../getactiveinfolist_fuzzer/project.xml | 25 ---- .../services/service/onstart_fuzzer/BUILD.gn | 74 ------------ .../service/onstart_fuzzer/corpus/init | 14 --- .../service/onstart_fuzzer/onstart_fuzzer.cpp | 101 ----------------- .../service/onstart_fuzzer/onstart_fuzzer.h | 22 ---- .../service/onstart_fuzzer/project.xml | 25 ---- .../processdeathobserver_fuzzer/BUILD.gn | 73 ------------ .../processdeathobserver_fuzzer/corpus/init | 14 --- .../processdeathobserver_fuzzer.cpp | 90 --------------- .../processdeathobserver_fuzzer.h | 22 ---- .../processdeathobserver_fuzzer/project.xml | 25 ---- .../BUILD.gn | 73 ------------ .../corpus/init | 14 --- .../project.xml | 25 ---- .../registerclientdeathrecipient_fuzzer.cpp | 107 ------------------ .../registerclientdeathrecipient_fuzzer.h | 22 ---- .../registerpermcallback_fuzzer/BUILD.gn | 73 ------------ .../registerpermcallback_fuzzer/corpus/init | 14 --- .../registerpermcallback_fuzzer/project.xml | 25 ---- .../registerpermcallback_fuzzer.cpp | 103 ----------------- .../registerpermcallback_fuzzer.h | 22 ---- .../service/reportactiveinfo_fuzzer/BUILD.gn | 74 ------------ .../reportactiveinfo_fuzzer/corpus/init | 14 --- .../reportactiveinfo_fuzzer/project.xml | 25 ---- .../reportactiveinfo_fuzzer.cpp | 105 ----------------- .../reportactiveinfo_fuzzer.h | 22 ---- .../reportonchangedata_fuzzer/BUILD.gn | 74 ------------ .../reportonchangedata_fuzzer/corpus/init | 14 --- .../reportonchangedata_fuzzer/project.xml | 25 ---- .../reportonchangedata_fuzzer.cpp | 103 ----------------- .../reportonchangedata_fuzzer.h | 22 ---- .../reportsensorsysevent_fuzzer/BUILD.gn | 73 ------------ .../reportsensorsysevent_fuzzer/corpus/init | 14 --- .../reportsensorsysevent_fuzzer/project.xml | 25 ---- .../reportsensorsysevent_fuzzer.cpp | 107 ------------------ .../reportsensorsysevent_fuzzer.h | 22 ---- .../transferdatachannel_fuzzer/BUILD.gn | 74 ------------ .../transferdatachannel_fuzzer/corpus/init | 14 --- .../transferdatachannel_fuzzer/project.xml | 25 ---- .../transferdatachannel_fuzzer.cpp | 91 --------------- .../transferdatachannel_fuzzer.h | 22 ---- .../conversion/src/conversion_fft.cpp | 12 +- .../conversion/src/conversion_mfcc.cpp | 8 +- 64 files changed, 48 insertions(+), 2715 deletions(-) delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 9dd4e8bb..b6f97fdd 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -21,6 +21,12 @@ ohos_shared_library("libsensor") { "$SUBSYSTEM_DIR/frameworks/js/napi/include", "$SUBSYSTEM_DIR/utils/common/include", ] + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } defines = [ "APP_LOG_TAG = \"sensorJs\"", "LOG_DOMAIN = 0xD002700", @@ -31,12 +37,6 @@ ohos_shared_library("libsensor") { "src/sensor_napi_utils.cpp", "src/sensor_system_js.cpp", ] - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] external_deps = [ "bundle_framework:appexecfwk_base", diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index f7222ca6..d2e6af9d 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -91,9 +91,6 @@ ohos_shared_library("sensor_interface_native") { "src/sensor_algorithm.cpp", ] - configs = [ ":sensor_private_config" ] - public_configs = [ ":sensor_public_config" ] - branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -104,6 +101,9 @@ ohos_shared_library("sensor_interface_native") { ubsan = true } + configs = [ ":sensor_private_config" ] + public_configs = [ ":sensor_public_config" ] + deps = [ "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", "$SUBSYSTEM_DIR/frameworks/native:libsensor_ndk", diff --git a/interfaces/inner_api/sensor_agent_type.h b/interfaces/inner_api/sensor_agent_type.h index 22ceecb4..ac5cf63a 100644 --- a/interfaces/inner_api/sensor_agent_type.h +++ b/interfaces/inner_api/sensor_agent_type.h @@ -429,7 +429,7 @@ typedef struct AmbientLightData { * The value 1 means that there is magnet attraction, and 0 means the opposite. */ typedef struct HallData { - float status = 0.0; + float status = 0.0F; } HallData; /** diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 19c830f8..3d1fee9e 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -37,13 +37,6 @@ enum { SEVEN_DIMENSION = 7, DEFAULT_DIMENSION = 16 }; -const std::set g_sensorTypeTrigger = { - SENSOR_TYPE_ID_PROXIMITY, - SENSOR_TYPE_ID_DROP_DETECTION, - SENSOR_TYPE_ID_HALL, - SENSOR_TYPE_ID_HALL_EXT, - SENSOR_TYPE_ID_PROXIMITY1 -}; } // namespace int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) @@ -65,7 +58,8 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) .mode = event.mode, .dataLen = event.dataLen }; - if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_PROXIMITY || + sensorData.sensorTypeId == SENSOR_TYPE_ID_DROP_DETECTION) { sensorData.mode = SENSOR_ON_CHANGE; } CHKPR(sensorData.data, ERR_NO_INIT); diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn b/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn index c379e577..2528534f 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn @@ -26,7 +26,6 @@ ohos_fuzztest("SensorAgentFuzzTest") { "$SUBSYSTEM_DIR/interfaces/inner_api", "$SUBSYSTEM_DIR/frameworks/native/include", "$SUBSYSTEM_DIR/test/fuzztest/interfaces/sensoragent_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", ] cflags = [ @@ -40,13 +39,7 @@ ohos_fuzztest("SensorAgentFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - ] + external_deps = [ "c_utils:utils" ] } group("fuzztest") { diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index a7300584..675e90b5 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -15,61 +15,10 @@ #include "sensoragent_fuzzer.h" -#include -#include - -#include "accesstoken_kit.h" -#include "token_setproc.h" -#include "nativetoken_kit.h" -#include "securec.h" - #include "sensor_agent.h" #include "sensor_agent_type.h" -#include "sensor_errors.h" - -using namespace OHOS::HiviewDFX; -using namespace OHOS::Security::AccessToken; -using OHOS::Security::AccessToken::AccessTokenID; -namespace { -constexpr int64_t g_samplingInterval = 200000000; -constexpr int64_t g_reportInterval = 200000000; -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - CHKPV(perms); - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "SensorAgentFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} +#include +#include void SensorDataCallbackImpl(SensorEvent *event) { @@ -94,24 +43,34 @@ bool CheckSensorTypeId(int32_t sensorTypeId) return false; } -void SensorAgentFuzzTest(const uint8_t *data, size_t size) +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) { - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorTypeId = 0; - GetObject(sensorTypeId, data + startPos, size - startPos); + intptr_t sensorTypeId = reinterpret_cast(data); bool validSensorId = CheckSensorTypeId(sensorTypeId); - if (!validSensorId) { - sensorTypeId = SENSOR_TYPE_ID_ACCELEROMETER; - } SensorUser user; user.callback = SensorDataCallbackImpl; - SubscribeSensor(sensorTypeId, &user); - SetBatch(sensorTypeId, &user, g_samplingInterval, g_reportInterval); - ActivateSensor(sensorTypeId, &user); + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - DeactivateSensor(sensorTypeId, &user); - UnsubscribeSensor(sensorTypeId, &user); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/test/fuzztest/services/BUILD.gn b/test/fuzztest/services/BUILD.gn index c15f5661..6632a988 100644 --- a/test/fuzztest/services/BUILD.gn +++ b/test/fuzztest/services/BUILD.gn @@ -31,17 +31,6 @@ group("fuzztest") { "sensordisablestub_fuzzer:fuzztest", "sensorenablestub_fuzzer:fuzztest", "sensoronremoterequest_fuzzer:fuzztest", - "service/createsocketchannel_fuzzer:fuzztest", - "service/destroysensorchannel_fuzzer:fuzztest", - "service/getactiveinfolist_fuzzer:fuzztest", - "service/onstart_fuzzer:fuzztest", - "service/processdeathobserver_fuzzer:fuzztest", - "service/registerclientdeathrecipient_fuzzer:fuzztest", - "service/registerpermcallback_fuzzer:fuzztest", - "service/reportactiveinfo_fuzzer:fuzztest", - "service/reportonchangedata_fuzzer:fuzztest", - "service/reportsensorsysevent_fuzzer:fuzztest", - "service/transferdatachannel_fuzzer:fuzztest", "suspendsensorsstub_fuzzer:fuzztest", ] } diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn deleted file mode 100644 index 26378f39..00000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("CreateSocketChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/createsocketchannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/createsocketchannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "createsocketchannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":CreateSocketChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init b/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp deleted file mode 100644 index 06141b7c..00000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 "createsocketchannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool CreateSocketChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - int32_t clientFd = 0; - GetObject(clientFd, data, size); - g_service->CreateSocketChannel(g_remote, clientFd); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::CreateSocketChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h deleted file mode 100644 index 98a294f5..00000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 CREATE_SOCKET_CHANNEL_FUZZER_H -#define CREATE_SOCKET_CHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "createsocketchannel_fuzzer" - -#endif // CREATE_SOCKET_CHANNEL_FUZZER_H - diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml b/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn deleted file mode 100644 index 11f710e7..00000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("DestroySensorChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/destroysensorchannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/destroysensorchannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "destroysensorchannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":DestroySensorChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init b/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp b/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp deleted file mode 100644 index eb0b817d..00000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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 "destroysensorchannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool DestroySensorChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - g_service->DestroySensorChannel(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::DestroySensorChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h b/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h deleted file mode 100644 index 67dc3af3..00000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 ON_START_FUZZER_H -#define ON_START_FUZZER_H - -#define FUZZ_PROJECT_NAME "onstart_fuzzer" - -#endif // ON_START_FUZZER_H - diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml b/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn b/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn deleted file mode 100644 index 46dfb718..00000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("GetActiveInfoListFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/getactiveinfolist_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/getactiveinfolist_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "getactiveinfolist_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":GetActiveInfoListFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init b/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp b/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp deleted file mode 100644 index 1c07d73c..00000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 "getactiveinfolist_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool GetActiveInfoListFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - std::vector activeInfoList; - int32_t pid = 0; - GetObject(pid, data, size); - g_service->GetActiveInfoList(pid, activeInfoList); - g_service->SuspendSensors(pid); - g_service->ResumeSensors(pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::GetActiveInfoListFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h b/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h deleted file mode 100644 index e5b217b2..00000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 GET_ACTIVE_INFO_LIST_FUZZER_H -#define GET_ACTIVE_INFO_LIST_FUZZER_H - -#define FUZZ_PROJECT_NAME "getactiveinfolist_fuzzer" - -#endif // GET_ACTIVE_INFO_LIST_FUZZER_H - diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml b/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn b/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn deleted file mode 100644 index b524a801..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("OnStartFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/onstart_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/onstart_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "onstart_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":OnStartFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/onstart_fuzzer/corpus/init b/test/fuzztest/services/service/onstart_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp b/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp deleted file mode 100644 index 051ec4f0..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 "onstart_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool OnStartFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - g_service->OnStart(); - g_service->OnStop(); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::OnStartFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h b/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h deleted file mode 100644 index 67dc3af3..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 ON_START_FUZZER_H -#define ON_START_FUZZER_H - -#define FUZZ_PROJECT_NAME "onstart_fuzzer" - -#endif // ON_START_FUZZER_H - diff --git a/test/fuzztest/services/service/onstart_fuzzer/project.xml b/test/fuzztest/services/service/onstart_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn b/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn deleted file mode 100644 index e9614fc7..00000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ProcessDeathObserverFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/processdeathobserver_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/processdeathobserver_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "processdeathobserver_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ProcessDeathObserverFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init b/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp b/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp deleted file mode 100644 index b72d9c95..00000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 "processdeathobserver_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ProcessDeathObserverFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - g_service->ProcessDeathObserver(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ProcessDeathObserverFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h b/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h deleted file mode 100644 index ea80ae35..00000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 PROCESS_DEATH_OBSERVER_FUZZER_H -#define PROCESS_DEATH_OBSERVER_FUZZER_H - -#define FUZZ_PROJECT_NAME "processdeathobserver_fuzzer" - -#endif // PROCESS_DEATH_OBSERVER_FUZZER_H - diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml b/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn deleted file mode 100644 index 556816d2..00000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("RegisterClientDeathRecipientFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "registerclientdeathrecipient_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":RegisterClientDeathRecipientFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp deleted file mode 100644 index 221ddc9a..00000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 "registerclientdeathrecipient_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool RegisterClientDeathRecipientFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - int32_t pid = 0; - GetObject(pid, data, size); - g_service->RegisterClientDeathRecipient(g_remote, pid); - g_service->UnregisterClientDeathRecipient(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::RegisterClientDeathRecipientFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h deleted file mode 100644 index 0db8d7d7..00000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H -#define REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H - -#define FUZZ_PROJECT_NAME "registerclientdeathrecipient_fuzzer" - -#endif // REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H - diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn b/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn deleted file mode 100644 index ab0f298c..00000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("RegisterPermCallbackFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerpermcallback_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerpermcallback_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "registerpermcallback_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":RegisterPermCallbackFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init b/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml b/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp b/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp deleted file mode 100644 index 286f0b51..00000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 "registerpermcallback_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool RegisterPermCallbackFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - int32_t sensorId = 0; - GetObject(sensorId, data, size); - g_service->RegisterPermCallback(sensorId); - g_service->UnregisterPermCallback(); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::RegisterPermCallbackFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h b/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h deleted file mode 100644 index 4a9fcbe7..00000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 REGISTER_PERM_CALLBACK_FUZZER_H -#define REGISTER_PERM_CALLBACK_FUZZER_H - -#define FUZZ_PROJECT_NAME "registerpermcallback_fuzzer" - -#endif // REGISTER_PERM_CALLBACK_FUZZER_H - diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn deleted file mode 100644 index da2e315b..00000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportActiveInfoFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportactiveinfo_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportactiveinfo_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportactiveinfo_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportActiveInfoFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init b/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml b/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp b/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp deleted file mode 100644 index f597b240..00000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 "reportactiveinfo_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportActiveInfoFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorId = 0; - startPos += GetObject(sensorId, data + startPos, size - startPos); - int32_t pid = 0; - startPos += GetObject(pid, data + startPos, size - startPos); - g_service->ReportActiveInfo(sensorId, pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportActiveInfoFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h b/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h deleted file mode 100644 index 5f783f64..00000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 REPOR_ACTIVE_INFO_FUZZER_H -#define REPOR_ACTIVE_INFO_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportactiveinfo_fuzzer" - -#endif // REPOR_ACTIVE_INFO_FUZZER_H - diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn deleted file mode 100644 index 2efd1e45..00000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportOnChangeDataFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportonchangedata_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportonchangedata_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportonchangedata_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportOnChangeDataFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init b/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml b/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp b/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp deleted file mode 100644 index 556f94dc..00000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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 "reportonchangedata_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportOnChangeDataFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - g_service->OnStart(); - int32_t sensorId = 0; - GetObject(sensorId, data, size); - g_service->ReportOnChangeData(sensorId); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportOnChangeDataFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h b/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h deleted file mode 100644 index e3e1091b..00000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 REPORT_ON_CHANGE_DATA_FUZZER_H -#define REPORT_ON_CHANGE_DATA_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportonchangedata_fuzzer" - -#endif // REPORT_ON_CHANGE_DATA_FUZZER_H - diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn deleted file mode 100644 index 0a1803a6..00000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportSensorSysEventFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportsensorsysevent_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportsensorsysevent_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportsensorsysevent_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportSensorSysEventFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp deleted file mode 100644 index c26f6f18..00000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 "reportsensorsysevent_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportSensorSysEventFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorId = 0; - startPos += GetObject(sensorId, data + startPos, size - startPos); - bool enable = false; - startPos += GetObject(enable, data + startPos, size - startPos); - int32_t pid = 0; - startPos += GetObject(pid, data + startPos, size - startPos); - g_service->ReportSensorSysEvent(sensorId, enable, pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportSensorSysEventFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h deleted file mode 100644 index 2472b099..00000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 REPORT_SENSOR_SYS_EVENT_FUZZER_H -#define REPORT_SENSOR_SYS_EVENT_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportsensorsysevent_fuzzer" - -#endif // REPORT_SENSOR_SYS_EVENT_FUZZER_H - diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn deleted file mode 100644 index a45b526a..00000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# 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. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("TransferDataChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/transferdatachannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/transferdatachannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "transferdatachannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":TransferDataChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init b/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd..00000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# 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 \ No newline at end of file diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml b/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp b/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp deleted file mode 100644 index 3874ebdb..00000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 "transferdatachannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -static sptr g_dataChannel = new (std::nothrow) SensorBasicDataChannel(); -} // namespace - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool TransferDataChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr || g_dataChannel == nullptr) { - return false; - } - g_service->TransferDataChannel(g_dataChannel, g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::TransferDataChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h b/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h deleted file mode 100644 index 36616538..00000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 TRANFER_DATA_CHANNEL_FUZZER_H -#define TRANFER_DATA_CHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "transferdatachannel_fuzzer" - -#endif // TRANFER_DATA_CHANNEL_FUZZER_H - diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index e2e135be..b40532fe 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp @@ -115,7 +115,7 @@ int32_t ConversionFFT::Process(const std::vector &values, int32_t &frame // reset pos to start of hop pos_ = para_.windowSize - para_.hopSize; /** shift buffer back by one hop size. */ - for (int32_t i = 0; i < pos_; ++i) { + for (int32_t i = 0; i < pos_; i++) { fftResult_.buffer[i] = fftResult_.buffer[i + para_.hopSize]; } isFftCalcFinish_ = true; @@ -142,7 +142,7 @@ float ConversionFFT::GetSpectralFlatness() const } float geometricMean = 0.0F; float arithmaticMean = 0.0F; - for (int32_t i = 0; i < bins_; ++i) { + for (int32_t i = 0; i < bins_; i++) { if (fftResult_.magnitudes[i] != 0) { geometricMean += logf(fftResult_.magnitudes[i]); } @@ -158,7 +158,7 @@ float ConversionFFT::GetSpectralCentroid() const { float x = 0.0F; float y = 0.0F; - for (int32_t i = 0; i < bins_; ++i) { + for (int32_t i = 0; i < bins_; i++) { x += fabs(fftResult_.magnitudes[i]) * i; y += fabs(fftResult_.magnitudes[i]); } @@ -199,15 +199,15 @@ float ConversionIFFT::Process(const std::vector &mags, const std::vector< } // add to output // shift back by one hop - for (int32_t i = 0; i < (para_.fftSize - para_.hopSize); ++i) { + for (int32_t i = 0; i < (para_.fftSize - para_.hopSize); i++) { fftResult_.buffer[i] = fftResult_.buffer[i + para_.hopSize]; } // clear the end chunk - for (int32_t i = 0; i < para_.hopSize; ++i) { + for (int32_t i = 0; i < para_.hopSize; i++) { fftResult_.buffer[i + para_.fftSize - para_.hopSize] = 0.0F; } // merge new output - for (int32_t i = 0; i < para_.fftSize; ++i) { + for (int32_t i = 0; i < para_.fftSize; i++) { fftResult_.buffer[i] += ifftOut_[i]; } } diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp index 126329b8..e1fdadd1 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp @@ -37,14 +37,14 @@ int32_t ConversionMfcc::HandleMelFilterAndLogSquare(const std::vector &po SEN_HILOGE("Invalid parameter"); return Sensors::PARAMETER_ERROR; } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { melBands_[i] = 0; for (uint32_t bin = 0; bin < numBins_; ++bin) { uint32_t idx = i + (bin * numFilters_); melBands_[i] += (melFilters_[idx] * powerSpectrum[bin]); } } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { // log the square melBands_[i] = (melBands_[i] > BANDS_MIN_THRESHOLD) ? log(melBands_[i] * melBands_[i]) : 0; } @@ -155,7 +155,7 @@ int32_t ConversionMfcc::CalcMelFilterBank(double sampleRate) double stepMel = (maxMel - minMel) / (numFilters_ + 1); std::vector filterHzPos(numFilters_ + 2); double nextMel = minMel; - for (uint32_t i = 0; i < (numFilters_ + 2); ++i) { + for (uint32_t i = 0; i < (numFilters_ + 2); i++) { filterHzPos[i] = OHOS::Sensors::ConvertSlaneyHz(nextMel); nextMel += stepMel; } @@ -164,7 +164,7 @@ int32_t ConversionMfcc::CalcMelFilterBank(double sampleRate) for (uint32_t bin = 0; bin < numBins_; ++bin) { binFs[bin] = stepHz * bin; } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { for (uint32_t j = 0; j < numBins_; ++j) { uint32_t idx = i + (j * numFilters_); if (SetMelFilters(idx, binFs[j], filterHzPos[i], filterHzPos[i + 1], -- Gitee From e5b0ea2c185181bc450e2d6bb3d9a919bb0173c2 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 3 Sep 2024 17:11:13 +0800 Subject: [PATCH 2/2] Code branch difference modification Signed-off-by: cff-gite Change-Id: If17f589da403715eb49cbf495078108a18e400ac --- .../sensoragent_fuzzer_20240903170434.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer_20240903171100.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer_20240903171101.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer_20240903171102.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer_20240903171104.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer_20240903171105.cpp | 81 +++++++++++++++++++ .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 10 +-- 7 files changed, 491 insertions(+), 5 deletions(-) create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903170434.cpp create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171100.cpp create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171101.cpp create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171102.cpp create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171104.cpp create mode 100644 .history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171105.cpp diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903170434.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903170434.cpp new file mode 100644 index 00000000..675e90b5 --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903170434.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171100.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171100.cpp new file mode 100644 index 00000000..60f564dc --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171100.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171101.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171101.cpp new file mode 100644 index 00000000..60f564dc --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171101.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171102.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171102.cpp new file mode 100644 index 00000000..60f564dc --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171102.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171104.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171104.cpp new file mode 100644 index 00000000..60f564dc --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171104.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171105.cpp b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171105.cpp new file mode 100644 index 00000000..60f564dc --- /dev/null +++ b/.history/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer_20240903171105.cpp @@ -0,0 +1,81 @@ +/* + * 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 "sensoragent_fuzzer.h" + +#include "sensor_agent.h" +#include "sensor_agent_type.h" +#include +#include + +void SensorDataCallbackImpl(SensorEvent *event) +{ + if (event == nullptr) { + return; + } +} + +bool CheckSensorTypeId(int32_t sensorTypeId) +{ + int32_t count = -1; + SensorInfo *sensorInfo = nullptr; + int32_t ret = GetAllSensors(&sensorInfo, &count); + if (ret != 0) { + return false; + } + for (int32_t i = 0; i < count; i++) { + if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { + return true; + } + } + return false; +} + +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) +{ + intptr_t sensorTypeId = reinterpret_cast(data); + bool validSensorId = CheckSensorTypeId(sensorTypeId); + SensorUser user; + user.callback = SensorDataCallbackImpl; + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + SensorAgentFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index 675e90b5..60f564dc 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -51,24 +51,24 @@ bool SensorAgentFuzzTest(const uint8_t *data, size_t size) user.callback = SensorDataCallbackImpl; int32_t ret = SubscribeSensor(sensorTypeId, &user); if (ret != 0) { - return validSensorId ? false : true; + return validSensorId ? false : true; } ret = SetBatch(sensorTypeId, &user, 200000000, 0); if (ret != 0) { - return validSensorId ? false : true; + return validSensorId ? false : true; } ret = ActivateSensor(sensorTypeId, &user); if (ret != 0) { - return validSensorId ? false : true; + return validSensorId ? false : true; } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); ret = DeactivateSensor(sensorTypeId, &user); if (ret != 0) { - return validSensorId ? false : true; + return validSensorId ? false : true; } ret = UnsubscribeSensor(sensorTypeId, &user); if (ret != 0) { - return validSensorId ? false : true; + return validSensorId ? false : true; } return true; } -- Gitee