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 0000000000000000000000000000000000000000..675e90b5f5838421f88d608d7f02e92282e0e124 --- /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 0000000000000000000000000000000000000000..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 --- /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 0000000000000000000000000000000000000000..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 --- /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 0000000000000000000000000000000000000000..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 --- /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 0000000000000000000000000000000000000000..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 --- /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 0000000000000000000000000000000000000000..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 --- /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/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 9dd4e8bb7ffc530b5efc1d3d30aff41b67685760..b6f97fdd62a3c0d30b1bed6d9ccb2d1ea1ae9ced 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 f7222ca6310c7d7a4d3ff58417dc673fc012a52b..d2e6af9dab513308a4e4ad39dc085d5b4ceb403d 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 22ceecb4469153ad4c0fcd08d3e1b70cfb6b3159..ac5cf63a51c723e1785ef0c4faedce975ee2790b 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 19c830f8c0206f3d5f00877d8be807e7711e785a..3d1fee9eb9ad8fb484c81488c68cbe4e479b7a38 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 c379e57756a2e37056481579c152ca5b2bdb37b7..2528534f1e256cecda7c72c1bfebe273a0dd2241 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 a73005845215847f705fd672dccaa33383dde8c5..60f564dc2e0b3f55cf267b1792d8ad8ee2f65268 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 c15f56612c0cab4322e63f7acfcac2b2024bb3e0..6632a988c1f2eeb1ca081d39119aa316002fd17a 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 26378f39c0bef12451c1310f573ae03e23226e71..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 06141b7ca9c3052a019c164e6a40dc0f1a5d000e..0000000000000000000000000000000000000000 --- 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 98a294f5076275a6ae7f5b30cd007455c1dfa608..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 11f710e7ce430ae16eddbcaf1377ca7b0e22df7a..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 eb0b817d4a2f53b8b7e0c4b30c5083f14d7abbe0..0000000000000000000000000000000000000000 --- 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 67dc3af37fdf06e139d430f50ece4937698f77cc..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 46dfb718eab61d01ae66b85549d3839baea4e7e9..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 1c07d73cda828cac780701cb70c4cea859625fc9..0000000000000000000000000000000000000000 --- 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 e5b217b275c4f042c960efc5d646cc3dcb60fd70..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 b524a8015d956fbbce83ff1d35e6868852605920..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 051ec4f0dbb25c5ac1727aa96e918ba53db20b9f..0000000000000000000000000000000000000000 --- 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 67dc3af37fdf06e139d430f50ece4937698f77cc..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 e9614fc719b4903c049715dc5c9fa1d83a4cb146..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 b72d9c95ec418f5c63f0f0802c8dd1fd7f32b47e..0000000000000000000000000000000000000000 --- 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 ea80ae35d43e42b07fa725168e45877f626b971a..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 556816d208c56d0bd36629c619c09aaa67576000..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 221ddc9a333507961bd09a617695aed7cfa25fea..0000000000000000000000000000000000000000 --- 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 0db8d7d7c34310fa47a15a486caf3e1472ede18a..0000000000000000000000000000000000000000 --- 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 ab0f298c78dc639d563d8c5c10383c139068f629..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 286f0b51bc70bdac7c3e481eef9821c9016ca80b..0000000000000000000000000000000000000000 --- 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 4a9fcbe746c6f06998d1ab72c0ffc82cedb79562..0000000000000000000000000000000000000000 --- 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 da2e315bd07b135ddc1e2f53969cd9be0b3231a2..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 f597b240baae7de5478f11f662c2a024e708d7ee..0000000000000000000000000000000000000000 --- 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 5f783f64e020ecd366b1edc3813c683164a9b0dc..0000000000000000000000000000000000000000 --- 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 2efd1e4545293f065aa3a371b2d665926803603e..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 556f94dcb0627a7f5ce7b70c4ff1baf0963d2be8..0000000000000000000000000000000000000000 --- 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 e3e1091b9afc6b19b0b96b55ee6503e8e3bb2b47..0000000000000000000000000000000000000000 --- 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 0a1803a6ae8d2ef42d013740b72b4744d94206b9..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 c26f6f18001c15bf10ce9e69cac830fc9c2b56f2..0000000000000000000000000000000000000000 --- 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 2472b099fca1ea594a484e6821e285d9ffcb843c..0000000000000000000000000000000000000000 --- 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 a45b526a2fe76e2cf8f1abec496dc302798116a2..0000000000000000000000000000000000000000 --- 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 e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- 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 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- 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 3874ebdb09e6f9acc6efe889721291f6ddb75e3a..0000000000000000000000000000000000000000 --- 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 36616538d2d41f0cb5656e32e1e9c0a2403c5613..0000000000000000000000000000000000000000 --- 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 e2e135bed8a4b476fb30e4d6fb3fe88537572f03..b40532fe084fac4bc5776a75660f990ee93b7b51 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 126329b81c9a86b2306334886037535325c6f29d..e1fdadd13c1a542b87f40f794ca085e7838e60a5 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],