From 2dbd16381ac3b326b0da685132d8c36bc156b656 Mon Sep 17 00:00:00 2001 From: wwx1101856 Date: Sat, 28 May 2022 15:31:20 +0800 Subject: [PATCH] add hc_node and access_to_ken_id dtfuzzer test Signed-off-by: wenfei --- test/BUILD.gn | 1 + test/fuzztest/BUILD.gn | 22 ++++ test/fuzztest/accesstokenid/BUILD.gn | 28 +++++ .../getftokenidcmdcorrect_fuzzer/BUILD.gn | 42 +++++++ .../getftokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../getftokenidcmdcorrect_fuzzer.cpp | 40 +++++++ .../getftokenidcmdcorrect_fuzzer.h | 21 ++++ .../getftokenidcmdcorrect_fuzzer/project.xml | 25 +++++ .../getftokenidcmderror_fuzzer/BUILD.gn | 42 +++++++ .../getftokenidcmderror_fuzzer/corpus/init | 14 +++ .../getftokenidcmderror_fuzzer.cpp | 40 +++++++ .../getftokenidcmderror_fuzzer.h | 21 ++++ .../getftokenidcmderror_fuzzer/project.xml | 25 +++++ .../gettokenidcmdcorrect_fuzzer/BUILD.gn | 42 +++++++ .../gettokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../gettokenidcmdcorrect_fuzzer.cpp | 42 +++++++ .../gettokenidcmdcorrect_fuzzer.h | 21 ++++ .../gettokenidcmdcorrect_fuzzer/project.xml | 25 +++++ .../gettokenidcmderror_fuzzer/BUILD.gn | 42 +++++++ .../gettokenidcmderror_fuzzer/corpus/init | 14 +++ .../gettokenidcmderror_fuzzer.cpp | 40 +++++++ .../gettokenidcmderror_fuzzer.h | 21 ++++ .../gettokenidcmderror_fuzzer/project.xml | 25 +++++ .../include/accesstokenidcmdcorrect.h | 44 ++++++++ .../include/accesstokenidcmderror.h | 44 ++++++++ .../setftokenidcmdcorrect_fuzzer/BUILD.gn | 42 +++++++ .../setftokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../setftokenidcmdcorrect_fuzzer/project.xml | 25 +++++ .../setftokenidcmdcorrect_fuzzer.cpp | 40 +++++++ .../setftokenidcmdcorrect_fuzzer.h | 21 ++++ .../setftokenidcmderror_fuzzer/BUILD.gn | 42 +++++++ .../setftokenidcmderror_fuzzer/corpus/init | 14 +++ .../setftokenidcmderror_fuzzer/project.xml | 25 +++++ .../setftokenidcmderror_fuzzer.cpp | 40 +++++++ .../setftokenidcmderror_fuzzer.h | 21 ++++ .../settokenidcmdcorrect_fuzzer/BUILD.gn | 41 +++++++ .../settokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../settokenidcmdcorrect_fuzzer/project.xml | 25 +++++ .../settokenidcmdcorrect_fuzzer.cpp | 42 +++++++ .../settokenidcmdcorrect_fuzzer.h | 21 ++++ .../settokenidcmderror_fuzzer/BUILD.gn | 42 +++++++ .../settokenidcmderror_fuzzer/corpus/init | 14 +++ .../settokenidcmderror_fuzzer/project.xml | 25 +++++ .../settokenidcmderror_fuzzer.cpp | 40 +++++++ .../settokenidcmderror_fuzzer.h | 21 ++++ .../src/accesstokenidcmdcorrect.cpp | 106 ++++++++++++++++++ .../src/accesstokenidcmderror.cpp | 106 ++++++++++++++++++ test/fuzztest/hc_node/BUILD.gn | 29 +++++ .../fuzztest/hc_node/hcenable_fuzzer/BUILD.gn | 37 ++++++ .../hc_node/hcenable_fuzzer/corpus/init | 13 +++ .../hcenable_fuzzer/hcenable_fuzzer.cpp | 65 +++++++++++ .../hc_node/hcenable_fuzzer/project.xml | 25 +++++ .../hchotdatalowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hchotdatalowerlimit_fuzzer/corpus/init | 13 +++ .../hchotdatalowerlimit_fuzzer.cpp | 65 +++++++++++ .../hchotdatalowerlimit_fuzzer/project.xml | 25 +++++ .../hchotdatawaterline_fuzzer/BUILD.gn | 37 ++++++ .../hchotdatawaterline_fuzzer/corpus/init | 13 +++ .../hchotdatawaterline_fuzzer.cpp | 65 +++++++++++ .../hchotdatawaterline_fuzzer/project.xml | 25 +++++ .../hchotnodelowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hchotnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hchotnodelowerlimit_fuzzer.cpp | 65 +++++++++++ .../hchotnodelowerlimit_fuzzer/project.xml | 25 +++++ .../hchotnodewaterline_fuzzer/BUILD.gn | 36 ++++++ .../hchotnodewaterline_fuzzer/corpus/init | 13 +++ .../hchotnodewaterline_fuzzer.cpp | 65 +++++++++++ .../hchotnodewaterline_fuzzer/project.xml | 25 +++++ .../hcwarmdatalowerlimit_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmdatalowerlimit_fuzzer/corpus/init | 13 +++ .../hcwarmdatalowerlimit_fuzzer.cpp | 65 +++++++++++ .../hcwarmdatalowerlimit_fuzzer/project.xml | 25 +++++ .../hcwarmdatawaterline_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmdatawaterline_fuzzer/corpus/init | 13 +++ .../hcwarmdatawaterline_fuzzer.cpp | 65 +++++++++++ .../hcwarmdatawaterline_fuzzer/project.xml | 25 +++++ .../hcwarmnodelowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hcwarmnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hcwarmnodelowerlimit_fuzzer.cpp | 65 +++++++++++ .../hcwarmnodelowerlimit_fuzzer/project.xml | 25 +++++ .../hcwarmnodewaterline_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmnodewaterline_fuzzer/corpus/init | 13 +++ .../hcwarmnodewaterline_fuzzer.cpp | 65 +++++++++++ .../hcwarmnodewaterline_fuzzer/project.xml | 25 +++++ 84 files changed, 2775 insertions(+) create mode 100644 test/fuzztest/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h create mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmderror.h create mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp create mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp create mode 100644 test/fuzztest/hc_node/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcenable_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcenable_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hcenable_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hchotdatawaterline_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hchotdatawaterline_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hchotdatawaterline_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hchotnodewaterline_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hchotnodewaterline_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hchotnodewaterline_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/project.xml create mode 100644 test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/BUILD.gn create mode 100644 test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/corpus/init create mode 100644 test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp create mode 100644 test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/project.xml diff --git a/test/BUILD.gn b/test/BUILD.gn index 5964ac0..747fc28 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 0000000..e95c330 --- /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 0000000..aa82ac2 --- /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 0000000..b9bbbf2 --- /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 0000000..58ee85e --- /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 0000000..fd0d5d7 --- /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 0000000..314fb9d --- /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 0000000..27c26d1 --- /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 0000000..fda5dce --- /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 0000000..58ee85e --- /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 0000000..235306a --- /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 0000000..60a4804 --- /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 0000000..27c26d1 --- /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 0000000..51af0fd --- /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 0000000..58ee85e --- /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 0000000..9bee2a9 --- /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 0000000..2ac8751 --- /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 0000000..6e8ad2c --- /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 0000000..2131812 --- /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 0000000..58ee85e --- /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 0000000..02242b6 --- /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 0000000..0545956 --- /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 0000000..6e8ad2c --- /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 0000000..d626a76 --- /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 0000000..0ce6f09 --- /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 0000000..916f7dd --- /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 0000000..58ee85e --- /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 0000000..27c26d1 --- /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 0000000..4fea690 --- /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 0000000..0b440c2 --- /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 0000000..f15c87e --- /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 0000000..58ee85e --- /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 0000000..27c26d1 --- /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 0000000..cce1d22 --- /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 0000000..3ab67c5 --- /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 0000000..f447473 --- /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 0000000..58ee85e --- /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 0000000..6e8ad2c --- /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 0000000..602c55f --- /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 0000000..4cc82ca --- /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 0000000..126f61f --- /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 0000000..58ee85e --- /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 0000000..6e8ad2c --- /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 0000000..fcb9cfa --- /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 0000000..78627a8 --- /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 0000000..808820a --- /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 0000000..f840f90 --- /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 0000000..13df32a --- /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 0000000..d2edc28 --- /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 0000000..6703f24 --- /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 0000000..7c7c9f0 --- /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 0000000..6e8ad2c --- /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 0000000..dc889e8 --- /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 0000000..6703f24 --- /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 0000000..8a1af0c --- /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 0000000..6e8ad2c --- /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 0000000..ba64e31 --- /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 0000000..6703f24 --- /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 0000000..189b67b --- /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 0000000..6e8ad2c --- /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 0000000..2ff4a14 --- /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 0000000..6703f24 --- /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 0000000..5799c61 --- /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 0000000..6e8ad2c --- /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 0000000..f313858 --- /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 0000000..6703f24 --- /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 0000000..2ef9b15 --- /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 0000000..6e8ad2c --- /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 0000000..2a1f7fe --- /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 0000000..1b91014 --- /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 0000000..9691fba --- /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 0000000..6e8ad2c --- /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 0000000..76517cb --- /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 0000000..1b91014 --- /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 0000000..040152f --- /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 0000000..6e8ad2c --- /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 0000000..11d6cbf --- /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 0000000..6703f24 --- /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 0000000..e5d3b23 --- /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 0000000..6e8ad2c --- /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 0000000..82873d4 --- /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 0000000..6703f24 --- /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 0000000..4c19bc2 --- /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 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee