diff --git a/test/BUILD.gn b/test/BUILD.gn index 5964ac0f69b2352fab2d3e36d58ed0a863109b8b..747fc28a36b238163558f3b7dc5966df46d788c0 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -46,6 +46,7 @@ group("linuxkerneltest") { deps = [ ":accesstokenid_test", ":init_runtest", + "fuzztest:fuzztest", ] } } diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e95c3307f024e86b4d38c3d69a2ba3c7da2b21a7 --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,22 @@ +# 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. + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + "accesstokenid:fuzztest", + "hc_node:fuzztest", + ] +} diff --git a/test/fuzztest/accesstokenid/BUILD.gn b/test/fuzztest/accesstokenid/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..aa82ac29138f2ed60a1239d1232a9eaa9bc69169 --- /dev/null +++ b/test/fuzztest/accesstokenid/BUILD.gn @@ -0,0 +1,28 @@ +# 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. + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + "getftokenidcmdcorrect_fuzzer:GetfTokenidCmdCorrectFuzzTest", + "getftokenidcmderror_fuzzer:GetfTokenidCmdErrorFuzzTest", + "gettokenidcmdcorrect_fuzzer:GetTokenidCmdCorrectFuzzTest", + "gettokenidcmderror_fuzzer:GetTokenidCmdErrorFuzzTest", + "setftokenidcmdcorrect_fuzzer:SetfTokenidCmdCorrectFuzzTest", + "setftokenidcmderror_fuzzer:SetfTokenidCmdErrorFuzzTest", + "settokenidcmdcorrect_fuzzer:SetTokenidCmdCorrectFuzzTest", + "settokenidcmderror_fuzzer:SetTokenidCmdErrorFuzzTest", + ] +} diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b9bbbf22c880cb2b72ef7e490e5380e5e796e505 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("GetfTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmdcorrect.cpp", + "getftokenidcmdcorrect_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetfTokenidCmdCorrectFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/corpus/init b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd0d5d7b609767cabf34c9b2d4266dcaa0d54173 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmdcorrect.h" +#include "getftokenidcmdcorrect_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetfTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetfTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..314fb9de7c525f6c9b9f505e443a65ef65167b32 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H +#define TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "getftokenidcmdcorrect_fuzzer" + +#endif // TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/project.xml b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fda5dce486cc0c21abc02b81afdbdad768e527db --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("GetfTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmderror.cpp", + "getftokenidcmderror_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetfTokenidCmdErrorFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/corpus/init b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..235306a085b1123fbfde99e4bcbfea5d653f3b0c --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmderror.h" +#include "getftokenidcmderror_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetfTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetfTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..60a480440c7588d392b2e644b5f8cd8c7e103dbd --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H +#define TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "getftokenidcmderror_fuzzer" + +#endif // TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/project.xml b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..51af0fd3a886087149b502f87a218194b80eccb0 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("GetTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmdcorrect.cpp", + "gettokenidcmdcorrect_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetTokenidCmdCorrectFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/corpus/init b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bee2a94697f33c9c9c3380b302cbbb48fc5a8f3 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,42 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcmdcorrect.h" +#include "gettokenidcmdcorrect_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2ac8751939bb9810ce3ba007307b1ea178bd29b4 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H +#define TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenidcmdcorrect_fuzzer" + +#endif // TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/project.xml b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2131812419bbe780acfa9e41024a4bf6c2485506 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("GetTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmderror.cpp", + "gettokenidcmderror_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetTokenidCmdErrorFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/corpus/init b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..02242b6aa06d41e3785affcf69a78dc351c980e7 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmderror.h" +#include "gettokenidcmderror_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetTokenidCmdErrorFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..05459560403be0fc8753911f1a381a7b49718a8e --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H +#define TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "gettokenidcmderror_fuzzer" + +#endif // TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/project.xml b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h new file mode 100644 index 0000000000000000000000000000000000000000..d626a76af4567a79525a1cd148d858c74092baf9 --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H +#define TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H + +namespace OHOS { +namespace Security { +namespace AccessToken { + constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; + constexpr unsigned int GET_TOKEN_ID = 1; + constexpr unsigned int SET_TOKEN_ID = 2; + constexpr unsigned int GET_FTOKEN_ID = 3; + constexpr unsigned int SET_FTOKEN_ID = 4; + +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_GET_FTOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_FTOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) + + int GetTokenid(unsigned long long *token); + int SetTokenid(unsigned long long *token); + int GetfTokenid(unsigned long long *ftoken); + int SetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h new file mode 100644 index 0000000000000000000000000000000000000000..0ce6f092984504ed5787955048c7658e31fa2cec --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H +#define TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H + +namespace OHOS { +namespace Security { +namespace AccessToken { + constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; + constexpr unsigned int GET_TOKEN_ID = 0; + constexpr unsigned int SET_TOKEN_ID = 0; + constexpr unsigned int GET_FTOKEN_ID = 0; + constexpr unsigned int SET_FTOKEN_ID = 0; + +#define ACCESS_TOKENID_GET_TOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_TOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_GET_FTOKENID \ + _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) +#define ACCESS_TOKENID_SET_FTOKENID \ + _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) + + int GetTokenid(unsigned long long *token); + int SetTokenid(unsigned long long *token); + int GetfTokenid(unsigned long long *ftoken); + int SetfTokenid(unsigned long long *ftoken); +} // namespace AccessToken +} // namespace Security +} // namespace OHOS + +#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..916f7dd7a8c75732815a022a7a65d794ce809426 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("SetfTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmdcorrect.cpp", + "setftokenidcmdcorrect_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetfTokenidCmdCorrectFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/corpus/init b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/project.xml b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fea69011c050efa51f4c8b5bb3d96396cf50859 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmdcorrect.h" +#include "setftokenidcmdcorrect_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetfTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetfTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0b440c269cba3ffe7fb0d3670ded743e405aec24 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H +#define TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "setftokenidcmdcorrect_fuzzer" + +#endif // TEST_FUZZTEST_SETFTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f15c87ef9755482871769502570e3823c707e8ef --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("SetfTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmderror.cpp", + "setftokenidcmderror_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetfTokenidCmdErrorFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/corpus/init b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/project.xml b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cce1d22623781e0a171fb18052e0b7f29d18d69c --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmderror.h" +#include "setftokenidcmderror_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetfTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetfTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetfTokenidCmdErrorFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3ab67c53750f506e4f4dafd58cc3fca9d9f7a005 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H +#define TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "setftokenidcmderror_fuzzer" + +#endif // TEST_FUZZTEST_SETFTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f44747352a2f0d60041814d3b1a3ad5e41d58f92 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,41 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("SetTokenidCmdCorrectFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "../src/accesstokenidcmdcorrect.cpp", + "settokenidcmdcorrect_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetTokenidCmdCorrectFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/corpus/init b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/project.xml b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..602c55f41a692f0e5188f152e60f70e044739ee8 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -0,0 +1,42 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcmdcorrect.h" +#include "settokenidcmdcorrect_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetTokenidCmdCorrectFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4cc82cad5a4a8084a7a1453e9e4c0d29cf8d29ab --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H +#define TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "settokenidcmdcorrect_fuzzer" + +#endif // TEST_FUZZTEST_SETTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..126f61fb147caa7a4f9be4efa8cd46870c12e897 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/accesstokenid" + +ohos_fuzztest("SetTokenidCmdErrorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcmderror.cpp", + "settokenidcmderror_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetTokenidCmdErrorFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/corpus/init b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/project.xml b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fcb9cfa51ea012ca568ee8db2d1dae282256c81f --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 +#include "accesstokenidcmderror.h" +#include "settokenidcmderror_fuzzer.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetTokenid(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetTokenidCmdErrorFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..78627a818e0a8220da26d642ebe2fc4fde28daa5 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H +#define TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H + +#define FUZZ_PROJECT_NAME "settokenidcmderror_fuzzer" + +#endif // TEST_FUZZTEST_SETTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp new file mode 100644 index 0000000000000000000000000000000000000000..808820ac3fef21cb612aee2807e1199a3833cea8 --- /dev/null +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp @@ -0,0 +1,106 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "accesstokenidcmdcorrect.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +const char *DEVACCESSTOKENID = "/dev/access_token_id"; + +int GetTokenid(unsigned long long *token) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int SetTokenid(unsigned long long *token) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int GetfTokenid(unsigned long long *ftoken) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int SetfTokenid(unsigned long long *ftoken) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f840f90b96b9df575b94f0cccfcfe6637c5962b1 --- /dev/null +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp @@ -0,0 +1,106 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "accesstokenidcmderror.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +const char *DEVACCESSTOKENID = "/dev/access_token_id"; + +int GetTokenid(unsigned long long *token) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int SetTokenid(unsigned long long *token) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int GetfTokenid(unsigned long long *ftoken) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} + +int SetfTokenid(unsigned long long *ftoken) +{ + int fd = open(DEVACCESSTOKENID, O_RDWR); + if (fd < 0) { + return -1; + } + + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); + if (ret) { + close(fd); + return -1; + } + + close(fd); + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/test/fuzztest/hc_node/BUILD.gn b/test/fuzztest/hc_node/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..13df32a50487b541cf6f8e2fa2a54dff6d7fd4ce --- /dev/null +++ b/test/fuzztest/hc_node/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + "hcenable_fuzzer:HcEnableFuzzTest", + "hchotdatalowerlimit_fuzzer:HcHotDataLowerLimitFuzzTest", + "hchotdatawaterline_fuzzer:HcHotDataWaterlineFuzzTest", + "hchotnodelowerlimit_fuzzer:HcHotNodeLowerLimitFuzzTest", + "hchotnodewaterline_fuzzer:HcHotNodeWaterLineFuzzTest", + "hcwarmdatalowerlimit_fuzzer:HcWarmDataLowerLimitFuzzTest", + "hcwarmdatawaterline_fuzzer:HcWarmDataWaterLineFuzzTest", + "hcwarmnodelowerlimit_fuzzer:HcWarmNodeLowerLimitFuzzTest", + "hcwarmnodewaterline_fuzzer:HcWarmNodeWaterLineFuzzTest", + ] +} diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hcenable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d2edc284413c9fd5bee27e37d57a04202f6a0d57 --- /dev/null +++ b/test/fuzztest/hc_node/hcenable_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcEnableFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hcenable_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcenable_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcEnableFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/corpus/init b/test/fuzztest/hc_node/hcenable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hcenable_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c7c9f0e399662e5014e4c540f0c66d176e4e3f8 --- /dev/null +++ b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_ENABLE = "/sys/fs/f2fs/loop1/hc_enable"; + +namespace OHOS { +bool HcEnableFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_ENABLE, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_ENABLE); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcEnableFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/project.xml b/test/fuzztest/hc_node/hcenable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hcenable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dc889e81f51aff9f36451443334aa72e454e8ff9 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcHotDataLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotdatalowerlimit_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotDataLowerLimitFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/corpus/init b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8a1af0c376f8c3c8237c2a1b0e168e8c297c9f3f --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_HOT_DATA_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_hot_data_lower_limit"; + +namespace OHOS { +bool HcHotDataLowerLimitFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_HOT_DATA_LOWER_LIMIT, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_HOT_DATA_LOWER_LIMIT); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcHotDataLowerLimitFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/project.xml b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ba64e31647d4f5dfd347a3455f279b825272a599 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcHotDataWaterlineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hchotdatawaterline_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotdatawaterline_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotDataWaterlineFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/corpus/init b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..189b67b6399f09f93c91fac02540dafc080c3d62 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_HOT_DATA_WATERLINE = "/sys/fs/f2fs/loop1/hc_hot_data_waterline"; + +namespace OHOS { +bool HcHotDataWaterlineFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_HOT_DATA_WATERLINE, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_HOT_DATA_WATERLINE); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcHotDataWaterlineFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/project.xml b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2ff4a14c5637fa87cfec535d7d3ec0145e778c05 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcHotNodeLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotnodelowerlimit_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotNodeLowerLimitFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/corpus/init b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5799c61c7c09a236ebedc3b99d08dd78fba238f4 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_HOT_NODE_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_hot_node_lower_limit"; + +namespace OHOS { +bool HcHotNodeLowerLimitFuzzTest(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_HOT_NODE_LOWER_LIMIT, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_HOT_NODE_LOWER_LIMIT); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcHotNodeLowerLimitFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/project.xml b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f31385874a9b6083cd6d91b7cb73d8e42bc23fc4 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcHotNodeWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hchotnodewaterline_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hchotnodewaterline_fuzzer.cpp" ] +} +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcHotNodeWaterLineFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/corpus/init b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ef9b15343db670326512f975da9b1f78954e6b6 --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_HOT_NODE_WATERLINE = "/sys/fs/f2fs/loop1/hc_hot_node_waterline"; + +namespace OHOS { +bool HcHotNodeWaterlineFuzzTest(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_HOT_NODE_WATERLINE, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_HOT_NODE_WATERLINE); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcHotNodeWaterlineFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/project.xml b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2a1f7fe48ba897e73f7e0e3dcb4f6194dfcfbe26 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcWarmDataLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmdatalowerlimit_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmDataLowerLimitFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/corpus/init b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9691fbaa026633f9d49adee860a7eb893d48f01a --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_WARM_DATA_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_warm_data_lower_limit"; + +namespace OHOS { +bool HcWarmDataLowerLimitFuzzTest(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_WARM_DATA_LOWER_LIMIT, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_WARM_DATA_LOWER_LIMIT); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcWarmDataLowerLimitFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/project.xml b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..76517cb8d525ffa8f858b0861c88113b57c81ad8 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcWarmDataWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmdatawaterline_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmDataWaterLineFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/corpus/init b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..040152f8453c07c18f5e669a897f3b78ebbae7af --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_WARM_DATA_WATERLINE = "/sys/fs/f2fs/loop1/hc_warm_data_waterline"; + +namespace OHOS { +bool HcWarmDataWaterLineFuzzTest(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_WARM_DATA_WATERLINE, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_WARM_DATA_WATERLINE); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcWarmDataWaterLineFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/project.xml b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..11d6cbfbd783b243255bb9ae63a7d87e812cd5b7 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcWarmNodeLowerLimitFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmnodelowerlimit_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmNodeLowerLimitFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5d3b2315c9be5ea228f89adabe215a958d0c176 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_WARM_NODE_LOWER_LIMIT = "/sys/fs/f2fs/loop1/hc_warm_node_lower_limit"; + +namespace OHOS { +bool HcWarmNodeLowerLimit(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_WARM_NODE_LOWER_LIMIT, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_WARM_NODE_LOWER_LIMIT); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcWarmNodeLowerLimit(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..82873d4ac586384a52178f6522838403b9d7f09b --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# 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. + +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "linuxkerneltest/hc_node" + +ohos_fuzztest("HcWarmNodeWaterLineFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "hcwarmnodewaterline_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HcWarmNodeWaterLineFuzzTest" ] +} diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/corpus/init b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c19bc2767b246c728eed4361a19c7839d3690d0 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +const char *HC_WARM_NODE_WATERLINE = "/sys/fs/f2fs/loop1/hc_warm_node_waterline"; + +namespace OHOS { +bool HcWarmNodeLowerWaterLine(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + uint32_t length = size > sizeof(uint32_t) ? sizeof(uint32_t) : size; + int ret = access("/mnt/f2fs_mount/", F_OK); + if (ret < 0) { + system("mkdir -p /mnt/f2fs_mount/"); + system("mkfs.f2fs -d1 -t1 -O quota /data/image_f2fs"); + system("losetup /dev/block/loop1 /data/image_f2fs"); + system("mount -t f2fs /dev/block/loop1 /mnt/f2fs_mount/"); + } + + int fd = open(HC_WARM_NODE_WATERLINE, O_RDWR); + if (fd < 0) { + return false; + } + + ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", HC_WARM_NODE_WATERLINE); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::HcWarmNodeLowerWaterLine(data, size); + return 0; +} diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/project.xml b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +