diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index b2b911f1cf22ff99cc9e29fe87362c02bace878f..77cc6f8c2b32bd2bdcd0312313ab570e88eb3d4b 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -147,6 +147,48 @@ ohos_fuzztest("ReadFileInDirFuzzTest") { defines = [ "STARTUP_INIT_TEST" ] } +ohos_fuzztest("ServiceControlStartFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + deps = [ + "//base/startup/init_lite/interfaces/innerkits:libbegetutil", + "//base/startup/init_lite/services/param:param_client", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.cpp" ] + + defines = [ "STARTUP_INIT_TEST" ] +} + +ohos_fuzztest("ServiceControlStopFuzzTest") { + module_out_path = module_output_path + + include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ] + deps = [ + "//base/startup/init_lite/interfaces/innerkits:libbegetutil", + "//base/startup/init_lite/services/param:param_client", + ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.cpp" ] + + defines = [ "STARTUP_INIT_TEST" ] +} + ohos_fuzztest("SystemDumpParametersFuzzTest") { module_out_path = module_output_path diff --git a/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.cpp b/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0583bf5dc73be4ad9ab57143e48b76d7e937b378 --- /dev/null +++ b/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "ServiceControlStart_fuzzer.h" +#include "service_control.h" + +namespace OHOS { + bool FuzzServiceControlStart(const uint8_t* data, size_t size) + { + bool result = false; + if (!ServiceControl(reinterpret_cast(data)), START) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzServiceControlStart(data, size); + return 0; +} diff --git a/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.h b/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..777f29f5a8f88b099e925459c714d066b91adae5 --- /dev/null +++ b/test/fuzztest/ServiceControlStart_fuzzer/ServiceControlStart_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H +#define TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H +#define FUZZ_PROJECT_NAME "ServiceControlStart_fuzzer" +#endif diff --git a/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.cpp b/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..854b0dd4bcfbbcd94ee3ebeaccaa81237cc4fb44 --- /dev/null +++ b/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 "ServiceControlStop_fuzzer.h" +#include "service_control.h" + +namespace OHOS { + bool FuzzServiceControlStop(const uint8_t* data, size_t size) + { + bool result = false; + if (!ServiceControl(reinterpret_cast(data)), STOP) { + result = true; + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzServiceControlStop(data, size); + return 0; +} diff --git a/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.h b/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7d618901b057ed7abf4689da5220b69e0aec8a97 --- /dev/null +++ b/test/fuzztest/ServiceControlStop_fuzzer/ServiceControlStop_fuzzer.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H +#define TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H +#define FUZZ_PROJECT_NAME "ServiceControlStop_fuzzer" +#endif