diff --git a/test/fuzztest/services/BUILD.gn b/test/fuzztest/services/BUILD.gn index c15f56612c0cab4322e63f7acfcac2b2024bb3e0..c6b010aed736d3ad9a1cc6102ad2924113170040 100644 --- a/test/fuzztest/services/BUILD.gn +++ b/test/fuzztest/services/BUILD.gn @@ -18,10 +18,6 @@ import("//build/test.gni") group("fuzztest") { testonly = true deps = [ - "createdatachannelstub_fuzzer:fuzztest", - "createsocketchannelstub_fuzzer:fuzztest", - "destroydatachannelstub_fuzzer:fuzztest", - "destroysocketchannelstub_fuzzer:fuzztest", "disableactiveinfocbstub_fuzzer:fuzztest", "enableactiveinfocbstub_fuzzer:fuzztest", "getactiveinfoliststub_fuzzer:fuzztest", @@ -31,17 +27,12 @@ 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", ] -} +} \ No newline at end of file diff --git a/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp b/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp index f3f85d1b27041dfd8fc9d0785cb5ae1d44037e6d..8d1ffe485965493dda966a6b4ad3f04f2dff630c 100644 --- a/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp +++ b/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp @@ -62,12 +62,28 @@ void SetUpTestCase() delete[] perms; } +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; +} + bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) { SetUpTestCase(); MessageParcel datas; + int32_t fd = 0; + GetObject(fd, data, size); datas.WriteInterfaceToken(SENSOR_INTERFACE_TOKEN); - if (g_remote == nullptr) { + if (g_remote == nullptr || g_service == nullptr) { return false; } datas.WriteRemoteObject(g_remote); @@ -76,6 +92,15 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageOption option; g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::TRANSFER_DATA_CHANNEL), datas, reply, option); + datas.RewindRead(0); + g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::DESTROY_SENSOR_CHANNEL), + datas, reply, option); + datas.RewindRead(0); + g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::CREATE_SOCKET_CHANNEL), + datas, reply, option); + datas.RewindRead(0); + g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::DESTROY_SOCKET_CHANNEL), + datas, reply, option); return true; } } // namespace Sensors diff --git a/test/fuzztest/services/createsocketchannelstub_fuzzer/BUILD.gn b/test/fuzztest/services/createsocketchannelstub_fuzzer/BUILD.gn deleted file mode 100644 index 3b2e17977e69d5ad9838c126047d7b04e02cef58..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2023 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("CreateSocketChannelStubFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/createsocketchannelstub_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/createsocketchannelstub_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "createsocketchannelstub_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_shared", - "access_token:libtokensetproc_shared", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":CreateSocketChannelStubFuzzTest", - ] -} diff --git a/test/fuzztest/services/createsocketchannelstub_fuzzer/corpus/init b/test/fuzztest/services/createsocketchannelstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 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/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp b/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp deleted file mode 100644 index 597178347b4edba67d4fff4d5e66ac594a48b16e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2023 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 "createsocketchannelstub_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(); -const std::u16string SENSOR_INTERFACE_TOKEN = u"ISensorService"; -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 = "CreateSocketChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - MessageParcel datas; - datas.WriteInterfaceToken(SENSOR_INTERFACE_TOKEN); - if (g_remote == nullptr) { - return false; - } - datas.WriteRemoteObject(g_remote); - datas.RewindRead(0); - MessageParcel reply; - MessageOption option; - g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::CREATE_SOCKET_CHANNEL), - datas, reply, option); - 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::OnRemoteRequestFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.h b/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.h deleted file mode 100644 index b83e68b575e8fd1696d898517bef926f06dbf9b3..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2023 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_STUB_FUZZER_H -#define CREATE_SOCKET_CHANNEL_STUB_FUZZER_H - -#define FUZZ_PROJECT_NAME "createsocketchannelstub_fuzzer" - -#endif // CREATE_SOCKET_CHANNEL_STUB_FUZZER_H - diff --git a/test/fuzztest/services/createsocketchannelstub_fuzzer/project.xml b/test/fuzztest/services/createsocketchannelstub_fuzzer/project.xml deleted file mode 100644 index 53811f014e17dd5a94f7b3865facfc2aeb6ed19e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/destroydatachannelstub_fuzzer/BUILD.gn b/test/fuzztest/services/destroydatachannelstub_fuzzer/BUILD.gn deleted file mode 100644 index 7269a5e0687b7092a39d4605ddd893dab9810ae5..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2023 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("DestroyDataChannelStubFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/destroydatachannelstub_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/destroydatachannelstub_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "destroydatachannelstub_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_shared", - "access_token:libtokensetproc_shared", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":DestroyDataChannelStubFuzzTest", - ] -} diff --git a/test/fuzztest/services/destroydatachannelstub_fuzzer/corpus/init b/test/fuzztest/services/destroydatachannelstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 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/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp b/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp deleted file mode 100644 index 48284574661581782c1ac4c067e4a9ee93532928..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2023 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 "destroydatachannelstub_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(); -const std::u16string SENSOR_INTERFACE_TOKEN = u"ISensorService"; -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 = "DestroyDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - MessageParcel datas; - datas.WriteInterfaceToken(SENSOR_INTERFACE_TOKEN); - if (g_remote == nullptr) { - return false; - } - datas.WriteRemoteObject(g_remote); - datas.RewindRead(0); - MessageParcel reply; - MessageOption option; - g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::DESTROY_SENSOR_CHANNEL), - datas, reply, option); - 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::OnRemoteRequestFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.h b/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.h deleted file mode 100644 index 966eb49d74f188a325249029f985319ec0f32857..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2023 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 DESTROY_DATA_CHANNEL_STUB_FUZZER_H -#define DESTROY_DATA_CHANNEL_STUB_FUZZER_H - -#define FUZZ_PROJECT_NAME "destroydatachannelstub_fuzzer" - -#endif // DESTROY_DATA_CHANNEL_STUB_FUZZER_H - diff --git a/test/fuzztest/services/destroydatachannelstub_fuzzer/project.xml b/test/fuzztest/services/destroydatachannelstub_fuzzer/project.xml deleted file mode 100644 index 53811f014e17dd5a94f7b3865facfc2aeb6ed19e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/destroysocketchannelstub_fuzzer/BUILD.gn b/test/fuzztest/services/destroysocketchannelstub_fuzzer/BUILD.gn deleted file mode 100644 index 08288eabbdf7461da0abd1e07560bddd7811b922..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2023 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("DestroySocketChannelStubFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/destroysocketchannelstub_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/destroysocketchannelstub_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "destroysocketchannelstub_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_shared", - "access_token:libtokensetproc_shared", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":DestroySocketChannelStubFuzzTest", - ] -} diff --git a/test/fuzztest/services/destroysocketchannelstub_fuzzer/corpus/init b/test/fuzztest/services/destroysocketchannelstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 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/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp b/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp deleted file mode 100644 index 92d437548c2df79d01e65b524100fd62530f07b3..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2023 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 "destroysocketchannelstub_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(); -const std::u16string SENSOR_INTERFACE_TOKEN = u"ISensorService"; -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 = "DestroySocketChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - MessageParcel datas; - datas.WriteInterfaceToken(SENSOR_INTERFACE_TOKEN); - if (g_remote == nullptr) { - return false; - } - datas.WriteRemoteObject(g_remote); - datas.RewindRead(0); - MessageParcel reply; - MessageOption option; - g_service->OnRemoteRequest(static_cast(SensorInterfaceCode::DESTROY_SOCKET_CHANNEL), - datas, reply, option); - 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::OnRemoteRequestFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.h b/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.h deleted file mode 100644 index 6cd6dcb2d0a76a96761ba6f176067c456fa84f50..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2023 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 DESTROY_SOCKET_CHANNEL_STUB_FUZZER_H -#define DESTROY_SOCKET_CHANNEL_STUB_FUZZER_H - -#define FUZZ_PROJECT_NAME "destroysocketchannelstub_fuzzer" - -#endif // DESTROY_SOCKET_CHANNEL_STUB_FUZZER_H - diff --git a/test/fuzztest/services/destroysocketchannelstub_fuzzer/project.xml b/test/fuzztest/services/destroysocketchannelstub_fuzzer/project.xml deleted file mode 100644 index 53811f014e17dd5a94f7b3865facfc2aeb6ed19e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp index 06141b7ca9c3052a019c164e6a40dc0f1a5d000e..4f3fd9cf1f4c23c92cab050090f483ac80f13868 100644 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp +++ b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp @@ -78,12 +78,16 @@ void SetUpTestCase() bool CreateSocketChannelFuzzTest(const uint8_t *data, size_t size) { SetUpTestCase(); - if (g_remote == nullptr) { + if (g_remote == nullptr || g_service == nullptr) { return false; } int32_t clientFd = 0; GetObject(clientFd, data, size); g_service->CreateSocketChannel(g_remote, clientFd); + g_service->DestroySensorChannel(g_remote); + g_service->OnStart(); + g_service->OnStop(); + g_service->ProcessDeathObserver(g_remote); return true; } } // namespace Sensors 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/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/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 -