From 71352fec98d167366501c5c4b1118a5c166d45d8 Mon Sep 17 00:00:00 2001 From: wwx1101856 Date: Sat, 28 May 2022 15:31:20 +0800 Subject: [PATCH 01/13] add hc_node and access_to_ken_id dtfuzzer test Signed-off-by: wwx1101856 --- test/BUILD.gn | 1 + test/fuzztest/BUILD.gn | 13 +++ test/fuzztest/accesstokenid/BUILD.gn | 28 +++++ .../getftokenidcmdcorrect_fuzzer/BUILD.gn | 44 +++++++ .../getftokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../getftokenidcmdcorrect_fuzzer.cpp | 42 +++++++ .../getftokenidcmdcorrect_fuzzer.h | 21 ++++ .../getftokenidcmdcorrect_fuzzer/project.xml | 25 ++++ .../getftokenidcmderror_fuzzer/BUILD.gn | 44 +++++++ .../getftokenidcmderror_fuzzer/corpus/init | 14 +++ .../getftokenidcmderror_fuzzer.cpp | 42 +++++++ .../getftokenidcmderror_fuzzer.h | 21 ++++ .../getftokenidcmderror_fuzzer/project.xml | 25 ++++ .../gettokenidcmdcorrect_fuzzer/BUILD.gn | 44 +++++++ .../gettokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../gettokenidcmdcorrect_fuzzer.cpp | 44 +++++++ .../gettokenidcmdcorrect_fuzzer.h | 21 ++++ .../gettokenidcmdcorrect_fuzzer/project.xml | 25 ++++ .../gettokenidcmderror_fuzzer/BUILD.gn | 44 +++++++ .../gettokenidcmderror_fuzzer/corpus/init | 14 +++ .../gettokenidcmderror_fuzzer.cpp | 42 +++++++ .../gettokenidcmderror_fuzzer.h | 21 ++++ .../gettokenidcmderror_fuzzer/project.xml | 25 ++++ .../include/accesstokenidcmdcorrect.h | 42 +++++++ .../include/accesstokenidcmderror.h | 42 +++++++ .../setftokenidcmdcorrect_fuzzer/BUILD.gn | 44 +++++++ .../setftokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../setftokenidcmdcorrect_fuzzer/project.xml | 25 ++++ .../setftokenidcmdcorrect_fuzzer.cpp | 42 +++++++ .../setftokenidcmdcorrect_fuzzer.h | 21 ++++ .../setftokenidcmderror_fuzzer/BUILD.gn | 44 +++++++ .../setftokenidcmderror_fuzzer/corpus/init | 14 +++ .../setftokenidcmderror_fuzzer/project.xml | 25 ++++ .../setftokenidcmderror_fuzzer.cpp | 42 +++++++ .../setftokenidcmderror_fuzzer.h | 21 ++++ .../settokenidcmdcorrect_fuzzer/BUILD.gn | 43 +++++++ .../settokenidcmdcorrect_fuzzer/corpus/init | 14 +++ .../settokenidcmdcorrect_fuzzer/project.xml | 25 ++++ .../settokenidcmdcorrect_fuzzer.cpp | 44 +++++++ .../settokenidcmdcorrect_fuzzer.h | 21 ++++ .../settokenidcmderror_fuzzer/BUILD.gn | 44 +++++++ .../settokenidcmderror_fuzzer/corpus/init | 14 +++ .../settokenidcmderror_fuzzer/project.xml | 25 ++++ .../settokenidcmderror_fuzzer.cpp | 42 +++++++ .../settokenidcmderror_fuzzer.h | 21 ++++ .../src/accesstokenidcmdcorrect.cpp | 106 +++++++++++++++++ .../src/accesstokenidcmderror.cpp | 107 ++++++++++++++++++ test/fuzztest/hc_node/BUILD.gn | 20 ++++ .../fuzztest/hc_node/hcenable_fuzzer/BUILD.gn | 37 ++++++ .../hc_node/hcenable_fuzzer/corpus/init | 13 +++ .../hcenable_fuzzer/hcenable_fuzzer.cpp | 68 +++++++++++ .../hc_node/hcenable_fuzzer/project.xml | 25 ++++ .../hchotdatalowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hchotdatalowerlimit_fuzzer/corpus/init | 13 +++ .../hchotdatalowerlimit_fuzzer.cpp | 68 +++++++++++ .../hchotdatalowerlimit_fuzzer/project.xml | 25 ++++ .../hchotdatawaterline_fuzzer/BUILD.gn | 37 ++++++ .../hchotdatawaterline_fuzzer/corpus/init | 13 +++ .../hchotdatawaterline_fuzzer.cpp | 68 +++++++++++ .../hchotdatawaterline_fuzzer/project.xml | 25 ++++ .../hchotnodelowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hchotnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hchotnodelowerlimit_fuzzer.cpp | 68 +++++++++++ .../hchotnodelowerlimit_fuzzer/project.xml | 25 ++++ .../hchotnodewaterline_fuzzer/BUILD.gn | 36 ++++++ .../hchotnodewaterline_fuzzer/corpus/init | 13 +++ .../hchotnodewaterline_fuzzer.cpp | 68 +++++++++++ .../hchotnodewaterline_fuzzer/project.xml | 25 ++++ .../hcwarmdatalowerlimit_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmdatalowerlimit_fuzzer/corpus/init | 13 +++ .../hcwarmdatalowerlimit_fuzzer.cpp | 68 +++++++++++ .../hcwarmdatalowerlimit_fuzzer/project.xml | 25 ++++ .../hcwarmdatawaterline_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmdatawaterline_fuzzer/corpus/init | 13 +++ .../hcwarmdatawaterline_fuzzer.cpp | 68 +++++++++++ .../hcwarmdatawaterline_fuzzer/project.xml | 25 ++++ .../hcwarmnodelowerlimit_fuzzer/BUILD.gn | 37 ++++++ .../hcwarmnodelowerlimit_fuzzer/corpus/init | 13 +++ .../hcwarmnodelowerlimit_fuzzer.cpp | 68 +++++++++++ .../hcwarmnodelowerlimit_fuzzer/project.xml | 25 ++++ .../hcwarmnodewaterline_fuzzer/BUILD.gn | 36 ++++++ .../hcwarmnodewaterline_fuzzer/corpus/init | 13 +++ .../hcwarmnodewaterline_fuzzer.cpp | 68 +++++++++++ .../hcwarmnodewaterline_fuzzer/project.xml | 25 ++++ 84 files changed, 2813 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..ab0c82e --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,13 @@ +# 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 += [ + "hc_node:fuzztest", + "accesstokenid: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..14c9d07 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn @@ -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. + +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..d857ad0 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_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. + */ + +#include +#include "getftokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcmdcorrect.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..78c3c07 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn @@ -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. + +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..1224144 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_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. + */ + +#include +#include "getftokenidcmderror_fuzzer.h" +#include "accesstokenidcmderror.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..b51b672 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -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. + +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..b636f47 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -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. + reinterpret_cast + static_cast + */ + +#include +#include "gettokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcmdcorrect.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..cb295f0 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn @@ -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. + +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..b7c6210 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_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. + */ + +#include +#include "gettokenidcmderror_fuzzer.h" +#include "accesstokenidcmderror.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..e390e5a --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h @@ -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. + */ + +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) + + const char *DEVACCESSTOKENID = "/dev/access_token_id"; + + 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 diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h new file mode 100644 index 0000000..36dbb03 --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h @@ -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. + */ + +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) + + const char *DEVACCESSTOKENID = "/dev/access_token_id"; + + 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 diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn new file mode 100644 index 0000000..582b61b --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn @@ -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. + +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..51655e5 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_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. + */ + +#include +#include "setftokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcmdcorrect.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..dcdcc97 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn @@ -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. + +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..6711e99 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_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. + */ + +#include +#include "setftokenidcmderror_fuzzer.h" +#include "accesstokenidcmderror.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..086040d --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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..e4142f7 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -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. + reinterpret_cast + static_cast + */ + +#include +#include "settokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcmdcorrect.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..6c1350b --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn @@ -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. + +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..afba320 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_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. + */ + +#include +#include "settokenidcmderror_fuzzer.h" +#include "accesstokenidcmderror.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; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..c7170e0 --- /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 +#include "accesstokenidcmdcorrect.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { + +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..1d96b60 --- /dev/null +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp @@ -0,0 +1,107 @@ +/* + * 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 +#include "accesstokenidcmderror.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { + +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..efe266a --- /dev/null +++ b/test/fuzztest/hc_node/BUILD.gn @@ -0,0 +1,20 @@ +# 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..8575ba0 --- /dev/null +++ b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_ENABLE, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_enable*/ + 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..309d1a1 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_HOT_DATA_LOWER_LIMIT, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hcHotDataLowerLimit*/ + 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..0525485 --- /dev/null +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_HOT_DATA_WATERLINE, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + 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..845d18e --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_HOT_NODE_LOWER_LIMIT, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + 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..63a7bdd --- /dev/null +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_HOT_NODE_WATERLINE, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + 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..67dc002 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_WARM_DATA_LOWER_LIMIT, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..6b31536 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_WARM_DATA_WATERLINE, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + 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..ccd7541 --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_WARM_NODE_LOWER_LIMIT, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + 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..b389f4b --- /dev/null +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 + +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, read value : %d\n", HC_WARM_NODE_WATERLINE, value); + close(fd); + return false; + } + + ret = write(fd, data, length); + if (ret < 0) { + close(fd); + return false; + } + close(fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data hc_hot_data_lower_limit*/ + 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 From b59306331d9c0dfca6ca1f4ea4ca35e6928b5438 Mon Sep 17 00:00:00 2001 From: shimmer-5880 Date: Sat, 28 May 2022 17:57:54 +0800 Subject: [PATCH 02/13] modify code check --- test/fuzztest/BUILD.gn | 9 ++++++++ .../getftokenidcmdcorrect_fuzzer.cpp | 22 +++++++++---------- .../getftokenidcmderror_fuzzer.cpp | 22 +++++++++---------- .../gettokenidcmdcorrect_fuzzer.cpp | 22 +++++++++---------- .../gettokenidcmderror_fuzzer.cpp | 22 +++++++++---------- .../include/accesstokenidcmdcorrect.h | 14 +++++++----- .../include/accesstokenidcmderror.h | 14 +++++++----- .../setftokenidcmdcorrect_fuzzer.cpp | 22 +++++++++---------- .../setftokenidcmderror_fuzzer.cpp | 22 +++++++++---------- .../settokenidcmdcorrect_fuzzer.cpp | 22 +++++++++---------- .../settokenidcmderror_fuzzer.cpp | 22 +++++++++---------- .../src/accesstokenidcmdcorrect.cpp | 3 ++- .../src/accesstokenidcmderror.cpp | 4 ++-- test/fuzztest/hc_node/BUILD.gn | 9 ++++++++ .../hcenable_fuzzer/hcenable_fuzzer.cpp | 11 ++++------ .../hchotdatalowerlimit_fuzzer.cpp | 11 ++++------ .../hchotdatawaterline_fuzzer.cpp | 11 ++++------ .../hchotnodelowerlimit_fuzzer.cpp | 11 ++++------ .../hchotnodewaterline_fuzzer.cpp | 13 +++++------ .../hcwarmdatalowerlimit_fuzzer.cpp | 11 ++++------ .../hcwarmdatawaterline_fuzzer.cpp | 11 ++++------ .../hcwarmnodelowerlimit_fuzzer.cpp | 11 ++++------ .../hcwarmnodewaterline_fuzzer.cpp | 11 ++++------ 23 files changed, 155 insertions(+), 175 deletions(-) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index ab0c82e..7a5a05e 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -1,3 +1,12 @@ +# 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. diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp index d857ad0..fd0d5d7 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "getftokenidcmdcorrect_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::GetfTokenidCmdCorrectFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp index 1224144..235306a 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "getftokenidcmderror_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::GetfTokenidCmdCorrectFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp index b636f47..9bee2a9 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -16,29 +16,27 @@ */ #include -#include "gettokenidcmdcorrect_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::GetTokenidCmdCorrectFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp index b7c6210..02242b6 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "gettokenidcmderror_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::GetTokenidCmdErrorFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h index e390e5a..d626a76 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h @@ -12,6 +12,8 @@ * 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 { @@ -22,17 +24,15 @@ namespace AccessToken { constexpr unsigned int GET_FTOKEN_ID = 3; constexpr unsigned int SET_FTOKEN_ID = 4; - #define ACCESS_TOKENID_GET_TOKENID \ +#define ACCESS_TOKENID_GET_TOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_SET_TOKENID \ +#define ACCESS_TOKENID_SET_TOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_GET_FTOKENID \ +#define ACCESS_TOKENID_GET_FTOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_SET_FTOKENID \ +#define ACCESS_TOKENID_SET_FTOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) - const char *DEVACCESSTOKENID = "/dev/access_token_id"; - int GetTokenid(unsigned long long *token); int SetTokenid(unsigned long long *token); int GetfTokenid(unsigned long long *ftoken); @@ -40,3 +40,5 @@ namespace AccessToken { } // 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 index 36dbb03..0ce6f09 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h @@ -12,6 +12,8 @@ * 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 { @@ -22,17 +24,15 @@ namespace AccessToken { constexpr unsigned int GET_FTOKEN_ID = 0; constexpr unsigned int SET_FTOKEN_ID = 0; - #define ACCESS_TOKENID_GET_TOKENID \ +#define ACCESS_TOKENID_GET_TOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_SET_TOKENID \ +#define ACCESS_TOKENID_SET_TOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_GET_FTOKENID \ +#define ACCESS_TOKENID_GET_FTOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) - #define ACCESS_TOKENID_SET_FTOKENID \ +#define ACCESS_TOKENID_SET_FTOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) - const char *DEVACCESSTOKENID = "/dev/access_token_id"; - int GetTokenid(unsigned long long *token); int SetTokenid(unsigned long long *token); int GetfTokenid(unsigned long long *ftoken); @@ -40,3 +40,5 @@ namespace AccessToken { } // namespace AccessToken } // namespace Security } // namespace OHOS + +#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp index 51655e5..4fea690 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "setftokenidcmdcorrect_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::SetfTokenidCmdCorrectFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp index 6711e99..cce1d22 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "setftokenidcmderror_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::SetfTokenidCmdErrorFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp index e4142f7..602c55f 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -16,29 +16,27 @@ */ #include -#include "settokenidcmdcorrect_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::SetTokenidCmdCorrectFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp index afba320..fcb9cfa 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -14,29 +14,27 @@ */ #include -#include "settokenidcmderror_fuzzer.h" #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); - } +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; +} } -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::SetTokenidCmdErrorFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp index c7170e0..429f69c 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,8 @@ 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); diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp index 1d96b60..7733953 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,8 @@ 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); @@ -101,7 +102,6 @@ int SetfTokenid(unsigned long long *ftoken) 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 index efe266a..13df32a 100644 --- a/test/fuzztest/hc_node/BUILD.gn +++ b/test/fuzztest/hc_node/BUILD.gn @@ -1,3 +1,12 @@ +# 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. diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp index 8575ba0..b934363 100644 --- a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcEnableFuzzer(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_enable*/ OHOS::HcEnableFuzzer(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp index 309d1a1..9546bea 100644 --- a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcHotDataLowerLimitFuzzer(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hcHotDataLowerLimit*/ OHOS::HcHotDataLowerLimitFuzzer(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp index 0525485..dc1f20c 100644 --- a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcHotDataWaterlineFuzzer(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_hot_data_lower_limit*/ OHOS::HcHotDataWaterlineFuzzer(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp index 845d18e..b00d4b2 100644 --- a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcHotNodeLowerLimitFuzzTest(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_hot_data_lower_limit*/ OHOS::HcHotNodeLowerLimitFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp index 63a7bdd..6bc7d51 100644 --- a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -26,7 +25,7 @@ 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); @@ -59,10 +58,8 @@ bool HcHotNodeWaterlineFuzzTest(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_hot_data_lower_limit*/ OHOS::HcHotNodeWaterlineFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp index 67dc002..de9b9a0 100644 --- a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcWarmDataLowerLimitFuzzTest(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::HcWarmDataLowerLimitFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp index 6b31536..a630225 100644 --- a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcWarmDataWaterLineFuzzTest(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data */ OHOS::HcWarmDataWaterLineFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp index ccd7541..bb5bf34 100644 --- a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcWarmNodeLowerLimit(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_hot_data_lower_limit*/ OHOS::HcWarmNodeLowerLimit(data, size); return 0; } diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp index b389f4b..9de60d6 100644 --- a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include #include @@ -59,10 +58,8 @@ bool HcWarmNodeLowerWaterLine(const uint8_t *data, size_t size) } } // namespace OHOS -/* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - /* Run your code on data hc_hot_data_lower_limit*/ OHOS::HcWarmNodeLowerWaterLine(data, size); return 0; } -- Gitee From efaa9279e01cfa315f9ee91e915506074299d7cd Mon Sep 17 00:00:00 2001 From: shimmer-5880 Date: Sat, 28 May 2022 18:26:49 +0800 Subject: [PATCH 03/13] modify build.gn format --- test/fuzztest/BUILD.gn | 2 +- .../accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn | 4 +--- .../accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn | 4 +--- .../accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn | 8 +++----- .../accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn | 8 +++----- .../accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn | 4 +--- .../accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn | 4 +--- .../accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn | 8 +++----- .../accesstokenid/settokenidcmderror_fuzzer/BUILD.gn | 8 +++----- 9 files changed, 17 insertions(+), 33 deletions(-) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 7a5a05e..e95c330 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -16,7 +16,7 @@ group("fuzztest") { deps = [] deps += [ - "hc_node:fuzztest", "accesstokenid:fuzztest", + "hc_node:fuzztest", ] } diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn index 14c9d07..b9bbbf2 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn @@ -20,9 +20,7 @@ ohos_fuzztest("GetfTokenidCmdCorrectFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer" - include_dirs = [ - "../include", - ] + include_dirs = [ "../include" ] cflags = [ "-g", diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn index 78c3c07..fda5dce 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn @@ -20,9 +20,7 @@ ohos_fuzztest("GetfTokenidCmdErrorFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer" - include_dirs = [ - "../include", - ] + include_dirs = [ "../include" ] cflags = [ "-g", diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn index b51b672..51af0fd 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -19,14 +19,12 @@ 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", - ] + + include_dirs = [ "../include" ] cflags = [ "-g", - "-O0", + "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn index cb295f0..2131812 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn @@ -19,14 +19,12 @@ 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", - ] + + include_dirs = [ "../include" ] cflags = [ "-g", - "-O0", + "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn index 582b61b..916f7dd 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn @@ -20,9 +20,7 @@ ohos_fuzztest("SetfTokenidCmdCorrectFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer" - include_dirs = [ - "../include", - ] + include_dirs = [ "../include" ] cflags = [ "-g", diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn index dcdcc97..f15c87e 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn @@ -20,9 +20,7 @@ ohos_fuzztest("SetfTokenidCmdErrorFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer" - include_dirs = [ - "../include", - ] + include_dirs = [ "../include" ] cflags = [ "-g", diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn index 086040d..f447473 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -19,14 +19,12 @@ 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", - ] + + include_dirs = [ "../include" ] cflags = [ "-g", - "-O0", + "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn index 6c1350b..126f61f 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn @@ -19,14 +19,12 @@ 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", - ] + + include_dirs = [ "../include" ] cflags = [ "-g", - "-O0", + "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", ] -- Gitee From 62ec80623e8f14512144a16fbbb8825784bd3985 Mon Sep 17 00:00:00 2001 From: shimmer-5880 Date: Sat, 28 May 2022 19:47:18 +0800 Subject: [PATCH 04/13] modify code check --- test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp | 1 - test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp index 429f69c..808820a 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp @@ -32,7 +32,6 @@ namespace OHOS { namespace Security { namespace AccessToken { - const char *DEVACCESSTOKENID = "/dev/access_token_id"; int GetTokenid(unsigned long long *token) diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp index 7733953..f840f90 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp @@ -32,7 +32,6 @@ namespace OHOS { namespace Security { namespace AccessToken { - const char *DEVACCESSTOKENID = "/dev/access_token_id"; int GetTokenid(unsigned long long *token) -- Gitee From 0ac86b211cb4c891f9f29bb5960c73a2ee22e74b Mon Sep 17 00:00:00 2001 From: cai_kuo Date: Mon, 30 May 2022 09:14:11 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp | 2 +- .../hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp | 2 +- .../hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp | 2 +- .../hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp | 2 +- .../hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp | 2 +- .../hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp | 2 +- .../hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp | 2 +- .../hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp | 2 +- .../hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp index b934363..5ef70b9 100644 --- a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcEnableFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_ENABLE, value); + printf("%s read fail, read value : %u\n", HC_ENABLE, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp index 9546bea..22044ca 100644 --- a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotDataLowerLimitFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_HOT_DATA_LOWER_LIMIT, value); + printf("%s read fail, read value : %u\n", HC_HOT_DATA_LOWER_LIMIT, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp index dc1f20c..b38ff44 100644 --- a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotDataWaterlineFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_HOT_DATA_WATERLINE, value); + printf("%s read fail, read value : %u\n", HC_HOT_DATA_WATERLINE, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp index b00d4b2..6939e7a 100644 --- a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotNodeLowerLimitFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_HOT_NODE_LOWER_LIMIT, value); + printf("%s read fail, read value : %u\n", HC_HOT_NODE_LOWER_LIMIT, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp index 6bc7d51..6bd4bd8 100644 --- a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotNodeWaterlineFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_HOT_NODE_WATERLINE, value); + printf("%s read fail, read value : %u\n", HC_HOT_NODE_WATERLINE, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp index de9b9a0..77f08dd 100644 --- a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmDataLowerLimitFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_WARM_DATA_LOWER_LIMIT, value); + printf("%s read fail, read value : %u\n", HC_WARM_DATA_LOWER_LIMIT, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp index a630225..1894e43 100644 --- a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmDataWaterLineFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_WARM_DATA_WATERLINE, value); + printf("%s read fail, read value : %u\n", HC_WARM_DATA_WATERLINE, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp index bb5bf34..1659fe9 100644 --- a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmNodeLowerLimit(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_WARM_NODE_LOWER_LIMIT, value); + printf("%s read fail, read value : %u\n", HC_WARM_NODE_LOWER_LIMIT, value); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp index 9de60d6..6e99eb6 100644 --- a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmNodeLowerWaterLine(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %d\n", HC_WARM_NODE_WATERLINE, value); + printf("%s read fail, read value : %u\n", HC_WARM_NODE_WATERLINE, value); close(fd); return false; } -- Gitee From 143cde378d8056715fccf67a157882238abbc62d Mon Sep 17 00:00:00 2001 From: cai_kuo Date: Mon, 30 May 2022 09:41:03 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp | 2 +- .../hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp | 2 +- .../hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp | 2 +- .../hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp | 2 +- .../hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp | 2 +- .../hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp | 2 +- .../hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp | 2 +- .../hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp | 2 +- .../hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp index 5ef70b9..7c7c9f0 100644 --- a/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcenable_fuzzer/hcenable_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcEnableFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_ENABLE, value); + printf("%s read fail\n", HC_ENABLE); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp index 22044ca..8a1af0c 100644 --- a/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatalowerlimit_fuzzer/hchotdatalowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotDataLowerLimitFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_HOT_DATA_LOWER_LIMIT, value); + printf("%s read fail\n", HC_HOT_DATA_LOWER_LIMIT); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp index b38ff44..189b67b 100644 --- a/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotdatawaterline_fuzzer/hchotdatawaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotDataWaterlineFuzzer(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_HOT_DATA_WATERLINE, value); + printf("%s read fail\n", HC_HOT_DATA_WATERLINE); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp index 6939e7a..5799c61 100644 --- a/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodelowerlimit_fuzzer/hchotnodelowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotNodeLowerLimitFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_HOT_NODE_LOWER_LIMIT, value); + printf("%s read fail\n", HC_HOT_NODE_LOWER_LIMIT); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp index 6bd4bd8..2ef9b15 100644 --- a/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hchotnodewaterline_fuzzer/hchotnodewaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcHotNodeWaterlineFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_HOT_NODE_WATERLINE, value); + printf("%s read fail\n", HC_HOT_NODE_WATERLINE); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp index 77f08dd..9691fba 100644 --- a/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatalowerlimit_fuzzer/hcwarmdatalowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmDataLowerLimitFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_WARM_DATA_LOWER_LIMIT, value); + printf("%s read fail\n", HC_WARM_DATA_LOWER_LIMIT); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp index 1894e43..040152f 100644 --- a/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmdatawaterline_fuzzer/hcwarmdatawaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmDataWaterLineFuzzTest(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_WARM_DATA_WATERLINE, value); + printf("%s read fail\n", HC_WARM_DATA_WATERLINE); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp index 1659fe9..e5d3b23 100644 --- a/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodelowerlimit_fuzzer/hcwarmnodelowerlimit_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmNodeLowerLimit(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_WARM_NODE_LOWER_LIMIT, value); + printf("%s read fail\n", HC_WARM_NODE_LOWER_LIMIT); close(fd); return false; } diff --git a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp index 6e99eb6..4c19bc2 100644 --- a/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp +++ b/test/fuzztest/hc_node/hcwarmnodewaterline_fuzzer/hcwarmnodewaterline_fuzzer.cpp @@ -43,7 +43,7 @@ bool HcWarmNodeLowerWaterLine(const uint8_t *data, size_t size) ret = read(fd, &value, sizeof(value)); if (ret < 0) { - printf("%s read fail, read value : %u\n", HC_WARM_NODE_WATERLINE, value); + printf("%s read fail\n", HC_WARM_NODE_WATERLINE); close(fd); return false; } -- Gitee From 5690c49625ba1283e908f77d8c465a28b9d48934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=98=8E=E8=BF=AA?= Date: Mon, 30 May 2022 11:28:35 +0000 Subject: [PATCH 07/13] =?UTF-8?q?!3=20=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20*=20=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fuzztest/accesstokenid/BUILD.gn | 10 ++ .../accessftokenidgrptest_fuzzer/BUILD.gn | 43 +++++ .../accessftokenidgrptest_fuzzer.cpp | 39 ++++ .../accessftokenidgrptest_fuzzer/corpus/init | 14 ++ .../accessftokenidgrptest_fuzzer/project.xml | 25 +++ .../BUILD.gn | 43 +++++ .../accessftokenidgrptestother_fuzzer.cpp | 39 ++++ .../corpus/init | 14 ++ .../project.xml | 25 +++ .../accessftokenidthreadtest_fuzzer/BUILD.gn | 43 +++++ .../accessftokenidthreadtest_fuzzer.cpp | 39 ++++ .../corpus/init | 14 ++ .../project.xml | 25 +++ .../accesstokenidgrptest_fuzzer/BUILD.gn | 43 +++++ .../accesstokenidgrptest_fuzzer.cpp | 39 ++++ .../accesstokenidgrptest_fuzzer/corpus/init | 14 ++ .../accesstokenidgrptest_fuzzer/project.xml | 25 +++ .../accesstokenidgrptestother_fuzzer/BUILD.gn | 43 +++++ .../accesstokenidgrptestother_fuzzer.cpp | 39 ++++ .../corpus/init | 14 ++ .../project.xml | 25 +++ .../accesstokenidthreadtest_fuzzer/BUILD.gn | 43 +++++ .../accesstokenidthreadtest_fuzzer.cpp | 39 ++++ .../corpus/init | 14 ++ .../project.xml | 25 +++ .../getftokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../getftokenidcmdcorrect_fuzzer.cpp | 3 +- .../getftokenidcmderror_fuzzer/BUILD.gn | 2 +- .../getftokenidcmderror_fuzzer.cpp | 4 +- .../getftokenidnullptr_fuzzer/BUILD.gn | 42 +++++ .../getftokenidnullptr_fuzzer/corpus/init | 14 ++ .../getftokenidnullptr_fuzzer.cpp} | 28 ++- .../getftokenidnullptr_fuzzer/project.xml | 25 +++ .../gettokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../gettokenidcmdcorrect_fuzzer.cpp | 3 +- .../gettokenidcmderror_fuzzer/BUILD.gn | 2 +- .../gettokenidcmderror_fuzzer.cpp | 4 +- .../gettokenidnullptr_fuzzer/BUILD.gn | 42 +++++ .../gettokenidnullptr_fuzzer/corpus/init | 14 ++ .../gettokenidnullptr_fuzzer.cpp} | 28 ++- .../gettokenidnullptr_fuzzer/project.xml | 25 +++ ...kenidcmderror.h => accessftokenidcommon.h} | 58 ++++-- ...enidcmdcorrect.h => accesstokenidcommon.h} | 56 ++++-- .../setftokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../setftokenidcmdcorrect_fuzzer.cpp | 3 +- .../setftokenidcmdcorrect_fuzzer.h | 21 --- .../setftokenidcmderror_fuzzer/BUILD.gn | 2 +- .../setftokenidcmderror_fuzzer.cpp | 4 +- .../setftokenidcmderror_fuzzer.h | 21 --- .../setftokenidnullptr_fuzzer/BUILD.gn | 42 +++++ .../setftokenidnullptr_fuzzer/corpus/init | 14 ++ .../setftokenidnullptr_fuzzer/project.xml | 25 +++ .../setftokenidnullptr_fuzzer.cpp} | 28 ++- .../settokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../settokenidcmdcorrect_fuzzer.cpp | 3 +- .../settokenidcmdcorrect_fuzzer.h | 21 --- .../settokenidcmderror_fuzzer/BUILD.gn | 2 +- .../settokenidcmderror_fuzzer.cpp | 4 +- .../settokenidcmderror_fuzzer.h | 21 --- .../settokenidnullptr_fuzzer/BUILD.gn | 42 +++++ .../settokenidnullptr_fuzzer/corpus/init | 14 ++ .../settokenidnullptr_fuzzer/project.xml | 25 +++ .../settokenidnullptr_fuzzer.cpp} | 28 ++- ...dcmderror.cpp => accessftokenidcommon.cpp} | 168 ++++++++++++++---- ...cmdcorrect.cpp => accesstokenidcommon.cpp} | 166 +++++++++++++---- 65 files changed, 1525 insertions(+), 223 deletions(-) create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/corpus/init rename test/fuzztest/accesstokenid/{gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h => getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp} (50%) create mode 100644 test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/corpus/init rename test/fuzztest/accesstokenid/{getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h => gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp} (50%) create mode 100644 test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml rename test/fuzztest/accesstokenid/include/{accesstokenidcmderror.h => accessftokenidcommon.h} (43%) rename test/fuzztest/accesstokenid/include/{accesstokenidcmdcorrect.h => accesstokenidcommon.h} (44%) delete mode 100644 test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h delete mode 100644 test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/project.xml rename test/fuzztest/accesstokenid/{gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h => setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp} (50%) delete mode 100644 test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h delete mode 100644 test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h create mode 100644 test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/BUILD.gn create mode 100644 test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/corpus/init create mode 100644 test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/project.xml rename test/fuzztest/accesstokenid/{getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h => settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp} (50%) rename test/fuzztest/accesstokenid/src/{accesstokenidcmderror.cpp => accessftokenidcommon.cpp} (33%) rename test/fuzztest/accesstokenid/src/{accesstokenidcmdcorrect.cpp => accesstokenidcommon.cpp} (33%) diff --git a/test/fuzztest/accesstokenid/BUILD.gn b/test/fuzztest/accesstokenid/BUILD.gn index aa82ac2..a637feb 100644 --- a/test/fuzztest/accesstokenid/BUILD.gn +++ b/test/fuzztest/accesstokenid/BUILD.gn @@ -16,13 +16,23 @@ group("fuzztest") { deps = [] deps += [ + "accessftokenidgrptest_fuzzer:AccessfTokenidGrpTestFuzzTest", + "accessftokenidgrptestother_fuzzer:AccessfTokenidGrpTestOtherFuzzTest", + "accessftokenidthreadtest_fuzzer:AccessfTokenidThreadTestFuzzTest", + "accesstokenidgrptest_fuzzer:AccessTokenidGrpTestFuzzTest", + "accesstokenidgrptestother_fuzzer:AccessTokenidGrpTestOtherFuzzTest", + "accesstokenidthreadtest_fuzzer:AccessTokenidThreadTestFuzzTest", "getftokenidcmdcorrect_fuzzer:GetfTokenidCmdCorrectFuzzTest", "getftokenidcmderror_fuzzer:GetfTokenidCmdErrorFuzzTest", + "getftokenidnullptr_fuzzer:GetfTokenidNullptrFuzzTest", "gettokenidcmdcorrect_fuzzer:GetTokenidCmdCorrectFuzzTest", "gettokenidcmderror_fuzzer:GetTokenidCmdErrorFuzzTest", + "gettokenidnullptr_fuzzer:GetTokenidNullptrFuzzTest", "setftokenidcmdcorrect_fuzzer:SetfTokenidCmdCorrectFuzzTest", "setftokenidcmderror_fuzzer:SetfTokenidCmdErrorFuzzTest", + "setftokenidnullptr_fuzzer:SetfTokenidNullptrFuzzTest", "settokenidcmdcorrect_fuzzer:SetTokenidCmdCorrectFuzzTest", "settokenidcmderror_fuzzer:SetTokenidCmdErrorFuzzTest", + "settokenidnullptr_fuzzer:SetTokenidNullptrFuzzTest", ] } diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn new file mode 100644 index 0000000..25f6b34 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessfTokenidGrpTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidgrptest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidGrpTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp new file mode 100644 index 0000000..4b5ff41 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessfTokenidGrpTestFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long ftokenId = *(reinterpret_cast(data)); + ret = AccessfTokenidGrpTest(&ftokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidGrpTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_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/accessftokenidgrptest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn new file mode 100644 index 0000000..d902d27 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessfTokenidGrpTestOtherFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidgrptestother_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidGrpTestOtherFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp new file mode 100644 index 0000000..ab3d4a5 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessfTokenidGrpTestOtherFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + unsigned long long ftokenId = *(reinterpret_cast(data)); + ret = AccessfTokenidGrpTestOther(&ftokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidGrpTestOtherFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_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/accessftokenidgrptestother_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn new file mode 100644 index 0000000..3bdbd2b --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessfTokenidThreadTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidthreadtest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidThreadTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp new file mode 100644 index 0000000..e08e1cc --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessfTokenidThreadTestFuzzTest(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 = AccessfTokenidThreadTest(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidThreadTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_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/accessftokenidthreadtest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn new file mode 100644 index 0000000..c83fa86 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessTokenidGrpTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidgrptest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidGrpTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp new file mode 100644 index 0000000..c3ef6ec --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessTokenidGrpTestFuzzTest(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 = AccessTokenidGrpTest(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidGrpTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_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/accesstokenidgrptest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn new file mode 100644 index 0000000..a7ffa34 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessTokenidGrpTestOtherFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidgrptestother_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidGrpTestOtherFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp new file mode 100644 index 0000000..df37658 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessTokenidGrpTestOtherFuzzTest(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 = AccessTokenidGrpTestOther(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidGrpTestOtherFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_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/accesstokenidgrptestother_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn new file mode 100644 index 0000000..b643bcf --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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("AccessTokenidThreadTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidthreadtest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidThreadTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp new file mode 100644 index 0000000..e96bb79 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool AccessTokenidThreadTestFuzzTest(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 = AccessTokenidThreadTest(&tokenId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidThreadTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_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/accesstokenidthreadtest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn index b9bbbf2..dd833e2 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accessftokenidcommon.cpp", "getftokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp index fd0d5d7..be0a7a5 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -14,8 +14,7 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "getftokenidcmdcorrect_fuzzer.h" +#include "accessftokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn index fda5dce..66b1aab 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accessftokenidcommon.cpp", "getftokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp index 235306a..6bdc1d0 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -14,8 +14,8 @@ */ #include -#include "accesstokenidcmderror.h" -#include "getftokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accessftokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000..a7aa727 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_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("GetfTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "getftokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetfTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_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.h b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp similarity index 50% rename from test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h rename to test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp index 2ac8751..00ab34c 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.h +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp @@ -11,11 +11,31 @@ * 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 */ -#ifndef TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H -#define TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H +#include +#include "accessftokenidcommon.h" -#define FUZZ_PROJECT_NAME "gettokenidcmdcorrect_fuzzer" +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetfTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} -#endif // TEST_FUZZTEST_GETTOKENIDCMDCORRECT_FUZZER_H +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetfTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn index 51af0fd..1e8be2f 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accesstokenidcommon.cpp", "gettokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp index 9bee2a9..22e9cdc 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -16,8 +16,7 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "gettokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn index 2131812..d72acf8 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accesstokenidcommon.cpp", "gettokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp index 02242b6..606dceb 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -14,8 +14,8 @@ */ #include -#include "accesstokenidcmderror.h" -#include "gettokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accesstokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000..912b3bc --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_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("GetTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "gettokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_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.h b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp similarity index 50% rename from test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h rename to test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp index 314fb9d..3acf32e 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.h +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp @@ -11,11 +11,31 @@ * 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 */ -#ifndef TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H -#define TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H +#include +#include "accesstokenidcommon.h" -#define FUZZ_PROJECT_NAME "getftokenidcmdcorrect_fuzzer" +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool GetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} -#endif // TEST_FUZZTEST_GETFTOKENIDCMDCORRECT_FUZZER_H +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h similarity index 43% rename from test/fuzztest/accesstokenid/include/accesstokenidcmderror.h rename to test/fuzztest/accesstokenid/include/accessftokenidcommon.h index 0ce6f09..9b1c75e 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -12,33 +12,53 @@ * 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 gettid() syscall(__NR_gettid) +#define ACCESS_TOKEN_ID_IOCTL_BASE 'A' + +#ifdef CMDERROR +constexpr unsigned int GET_FTOKEN_ID = 0; +constexpr unsigned int SET_FTOKEN_ID = 0; +#else +constexpr unsigned int GET_FTOKEN_ID = 3; +constexpr unsigned int SET_FTOKEN_ID = 4; +#endif + #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); +#define LIST_NUM 2 +#define TEST_VALUE 123 +#define CHILDREN_NUM 3 +#define WAIT_FOR_SHELL_OP_TIME 1 +#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1)) + +#define ACCESS_TOKEN_UID 3020 +#define ACCESS_TOKEN_GRPID 3020 + +#define ACCESS_TOKEN_OTHER_UID 1234 +#define ACCESS_TOKEN_OTHER_GRPID 1234 + +#define INVAL_TOKEN 0xffffffffffffffff + +int GetfTokenid(unsigned long long *ftoken); +int SetfTokenid(unsigned long long *ftoken); + +void SetUidAndGrp(); +void SetUidAndGrpOther(); +void GetCurfToken(unsigned long long *ftoken); +void ShowCurfToken(); +void SetRandfTokenAndCheck(unsigned long long *data_ftoken); +void fTokenTest(unsigned long long *data_ftoken); +void ThreadTest(unsigned long long *data_ftoken); +int AccessfTokenidThreadTest(unsigned long long *data_ftoken); +int AccessfTokenidGrpTest(unsigned long long *data_ftoken); +int AccessfTokenidGrpTestOther(unsigned long long *data_ftoken); } // namespace AccessToken } // namespace Security -} // namespace OHOS - -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h similarity index 44% rename from test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h rename to test/fuzztest/accesstokenid/include/accesstokenidcommon.h index d626a76..7f63066 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -12,33 +12,53 @@ * 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 gettid() syscall(__NR_gettid) +#define ACCESS_TOKEN_ID_IOCTL_BASE 'A' + +#ifdef CMDERROR +constexpr unsigned int GET_TOKEN_ID = 0; +constexpr unsigned int SET_TOKEN_ID = 0; +#else +constexpr unsigned int GET_TOKEN_ID = 1; +constexpr unsigned int SET_TOKEN_ID = 2; +#endif #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); + +#define LIST_NUM 2 +#define TEST_VALUE 123 +#define CHILDREN_NUM 3 +#define WAIT_FOR_SHELL_OP_TIME 1 +#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1)) + +#define ACCESS_TOKEN_UID 3020 +#define ACCESS_TOKEN_GRPID 3020 + +#define ACCESS_TOKEN_OTHER_UID 1234 +#define ACCESS_TOKEN_OTHER_GRPID 1234 + +#define INVAL_TOKEN 0xffffffffffffffff + +int GetTokenid(unsigned long long *token); +int SetTokenid(unsigned long long *token); + +void SetUidAndGrp(); +void SetUidAndGrpOther(); +void GetCurToken(unsigned long long *token); +void ShowCurToken(); +void SetRandTokenAndCheck(unsigned long long *data_token); +void TokenTest(unsigned long long *data_token); +void ThreadTest(unsigned long long *data_token); +int AccessTokenidThreadTest(unsigned long long *data_token); +int AccessTokenidGrpTest(unsigned long long *data_token); +int AccessTokenidGrpTestOther(unsigned long long *data_token); } // namespace AccessToken } // namespace Security } // namespace OHOS - -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn index 916f7dd..bdabf6f 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accessftokenidcommon.cpp", "setftokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp index 4fea690..ae8f76e 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -14,8 +14,7 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "setftokenidcmdcorrect_fuzzer.h" +#include "accessftokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h deleted file mode 100644 index 0b440c2..0000000 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 index f15c87e..00fb0ff 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accessftokenidcommon.cpp", "setftokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp index cce1d22..a54f213 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -14,8 +14,8 @@ */ #include -#include "accesstokenidcmderror.h" -#include "setftokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accessftokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h deleted file mode 100644 index 3ab67c5..0000000 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/setftokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000..0847e82 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_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("SetfTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "setftokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetfTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_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/setftokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp similarity index 50% rename from test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h rename to test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp index 0545956..b1f84cb 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.h +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp @@ -11,11 +11,31 @@ * 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 */ -#ifndef TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H -#define TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H +#include +#include "accessftokenidcommon.h" -#define FUZZ_PROJECT_NAME "gettokenidcmderror_fuzzer" +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetfTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} -#endif // TEST_FUZZTEST_GETTOKENIDCMDERROR_FUZZER_H +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetfTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn index f447473..0def899 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -29,7 +29,7 @@ ohos_fuzztest("SetTokenidCmdCorrectFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accesstokenidcommon.cpp", "settokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp index 602c55f..a090a6a 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -16,8 +16,7 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "settokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h deleted file mode 100644 index 4cc82ca..0000000 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 index 126f61f..037811e 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accesstokenidcommon.cpp", "settokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp index fcb9cfa..c6b7d1d 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -14,8 +14,8 @@ */ #include -#include "accesstokenidcmderror.h" -#include "settokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accesstokenidcommon.h" using namespace std; using namespace OHOS::Security::AccessToken; diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h deleted file mode 100644 index 78627a8..0000000 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/settokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000..3b78e95 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_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("SetTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "settokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000..58ee85e --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_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/settokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp similarity index 50% rename from test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h rename to test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp index 60a4804..cceb0a8 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.h +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp @@ -11,11 +11,31 @@ * 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 */ -#ifndef TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H -#define TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H +#include +#include "accesstokenidcommon.h" -#define FUZZ_PROJECT_NAME "getftokenidcmderror_fuzzer" +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace OHOS { +bool SetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} -#endif // TEST_FUZZTEST_GETFTOKENIDCMDERROR_FUZZER_H +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp similarity index 33% rename from test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp rename to test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp index f840f90..23caa80 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -15,33 +15,28 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmderror.h" +#include "accessftokenidcommon.h" namespace OHOS { namespace Security { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; -int GetTokenid(unsigned long long *token) +int GetfTokenid(unsigned long long *ftoken) { int fd = open(DEVACCESSTOKENID, O_RDWR); if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); if (ret) { close(fd); return -1; @@ -51,14 +46,14 @@ int GetTokenid(unsigned long long *token) return 0; } -int SetTokenid(unsigned long long *token) +int SetfTokenid(unsigned long long *ftoken) { int fd = open(DEVACCESSTOKENID, O_RDWR); if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); if (ret) { close(fd); return -1; @@ -68,37 +63,148 @@ int SetTokenid(unsigned long long *token) return 0; } -int GetfTokenid(unsigned long long *ftoken) +void SetUidAndGrp() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t size = WAIT_FOR_SHELL_OP_TIME; + gid_t list[LIST_NUM] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(size, list); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); - return 0; + return; } -int SetfTokenid(unsigned long long *ftoken) +void SetUidAndGrpOther() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t size = WAIT_FOR_SHELL_OP_TIME; + gid_t list[WAIT_FOR_SHELL_OP_TIME] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(size, list); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \r\n", ret); } - close(fd); + return; +} + +void GetCurfToken(unsigned long long *ftoken) +{ + GetfTokenid(ftoken); + return; +} + +void ShowCurfToken() +{ + unsigned long long ftoken = INVAL_TOKEN; + GetCurfToken(&ftoken); +} + +void SetRandfTokenAndCheck(unsigned long long *data_ftoken) +{ + pid_t pid = getpid(); + pid_t tid = gettid(); + unsigned long long ftoken = INVAL_TOKEN; + unsigned long long ftokenSet = *data_ftoken; + SetfTokenid(&ftokenSet); + + GetfTokenid(&ftoken); + if (ftoken != ftokenSet) { + printf("pid:%d tid:%d ftoken test failed, ftoken:%#llx ftokenSet:%#llx\n", + pid, tid, ftoken, ftokenSet); + } else { + printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llx ftokenSet:%#llx\n", + pid, tid, ftoken, ftokenSet); + } + + sleep(WAIT_FOR_SHELL_OP_TIME); + + GetfTokenid(&ftoken); + if (ftoken != ftokenSet) { + printf("pid:%d tid:%d ftoken test failed, ftoken:%#llx ftokenSet:%#llx\n", + pid, tid, ftoken, ftokenSet); + } else { + printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llx ftokenSet:%#llx\n", + pid, tid, ftoken, ftokenSet); + } + return; +} + +void *fTokenTest(void *data_ftoken) +{ + ShowCurfToken(); + + sleep(WAIT_FOR_SHELL_OP_TIME); + + SetRandfTokenAndCheck(reinterpret_cast(data_ftoken)); + return data_ftoken; +} + +void ThreadTest(void *data_ftoken) +{ + pthread_t id_1; + pthread_t id_2; + pthread_t id_3; + int ret = 0; + + ret = pthread_create(&id_1, NULL, fTokenTest, data_ftoken); + if(ret != 0) + { + return; + } + + ret = pthread_create(&id_2, NULL, fTokenTest, data_ftoken); + if(ret != 0) + { + return; + } + + ret = pthread_create(&id_3, NULL, fTokenTest, data_ftoken); + if(ret != 0) + { + return; + } + + pthread_join(id_1, NULL); + pthread_join(id_2, NULL); + pthread_join(id_3, NULL); + + return; +} + +int AccessfTokenidThreadTest(unsigned long long *data_ftoken) +{ + fTokenTest(reinterpret_cast(data_ftoken)); + ThreadTest(reinterpret_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTest(unsigned long long *data_ftoken) +{ + SetUidAndGrp(); + fTokenTest(reinterpret_cast(data_ftoken)); + ThreadTest(reinterpret_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTestOther(unsigned long long *data_ftoken) +{ + SetUidAndGrpOther(); + fTokenTest(reinterpret_cast(data_ftoken)); + ThreadTest(reinterpret_cast(data_ftoken)); return 0; } } // namespace AccessToken diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp similarity index 33% rename from test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp rename to test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp index 808820a..ead23fc 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -15,19 +15,14 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmdcorrect.h" +#include "accesstokenidcommon.h" namespace OHOS { namespace Security { @@ -40,13 +35,11 @@ int GetTokenid(unsigned long long *token) if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); if (ret) { close(fd); return -1; } - close(fd); return 0; } @@ -57,48 +50,159 @@ int SetTokenid(unsigned long long *token) 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) +void SetUidAndGrp() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t size = WAIT_FOR_SHELL_OP_TIME; + gid_t list[LIST_NUM] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(size, list); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); - return 0; + return; } -int SetfTokenid(unsigned long long *ftoken) +void SetUidAndGrpOther() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t size = WAIT_FOR_SHELL_OP_TIME; + gid_t list[WAIT_FOR_SHELL_OP_TIME] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(size, list); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); + return; +} + +void GetCurToken(unsigned long long *token) +{ + GetTokenid(token); + return; +} + +void ShowCurToken() +{ + unsigned long long token = INVAL_TOKEN; + GetCurToken(&token); +} + +void SetRandTokenAndCheck(unsigned long long *data_token) +{ + pid_t pid = getpid(); + pid_t tid = gettid(); + unsigned long long token = INVAL_TOKEN; + unsigned long long tokenSet = *data_token; + SetTokenid(&tokenSet); + + GetTokenid(&token); + + if (token != tokenSet) { + printf("pid:%d tid:%d token test failed, token:%#llx tokenSet:%#llx\n", + pid, tid, token, tokenSet); + } else { + printf("pid:%d tid:%d token test succeed, token:%#llx tokenSet:%#llx\n", + pid, tid, token, tokenSet); + } + + sleep(WAIT_FOR_SHELL_OP_TIME); + + GetTokenid(&token); + if (token != tokenSet) { + printf("pid:%d tid:%d token test failed, token:%#llx tokenSet:%#llx\n", + pid, tid, token, tokenSet); + } else { + printf("pid:%d tid:%d token test succeed, token:%#llx tokenSet:%#llx\n", + pid, tid, token, tokenSet); + } + return; +} + +void *TokenTest(void *data_token) +{ + ShowCurToken(); + + sleep(WAIT_FOR_SHELL_OP_TIME); + + SetRandTokenAndCheck(reinterpret_cast(data_token)); + + return data_token; +} + +void ThreadTest(void *data_token) +{ + pthread_t id_1; + pthread_t id_2; + pthread_t id_3; + int ret = 0; + + ret = pthread_create(&id_1, NULL, TokenTest, data_token); + if(ret != 0) + { + return; + } + + ret = pthread_create(&id_2, NULL, TokenTest, data_token); + if(ret != 0) + { + return; + } + + ret = pthread_create(&id_3, NULL, TokenTest, data_token); + if(ret != 0) + { + return; + } + + pthread_join(id_1, NULL); + pthread_join(id_2, NULL); + pthread_join(id_3, NULL); + + return; +} + +int AccessTokenidThreadTest(unsigned long long *data_token) +{ + TokenTest(reinterpret_cast(data_token)); + ThreadTest(reinterpret_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTest(unsigned long long *data_token) +{ + SetUidAndGrp(); + TokenTest(reinterpret_cast(data_token)); + ThreadTest(reinterpret_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTestOther(unsigned long long *data_token) +{ + SetUidAndGrpOther(); + TokenTest(reinterpret_cast(data_token)); + ThreadTest(reinterpret_cast(data_token)); return 0; } } // namespace AccessToken -- Gitee From 6c55be77bcbd2331689de0d550c451d870f3cf47 Mon Sep 17 00:00:00 2001 From: yang_mingdi Date: Tue, 31 May 2022 10:36:17 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/accessftokenidcommon.h | 10 ++++- .../include/accesstokenidcommon.h | 8 +++- .../src/accessftokenidcommon.cpp | 39 +++++++++---------- .../accesstokenid/src/accesstokenidcommon.cpp | 39 +++++++++---------- 4 files changed, 51 insertions(+), 45 deletions(-) diff --git a/test/fuzztest/accesstokenid/include/accessftokenidcommon.h b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h index 9b1c75e..00d54e4 100644 --- a/test/fuzztest/accesstokenid/include/accessftokenidcommon.h +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -13,10 +13,14 @@ * limitations under the License. */ +#ifndef ACCESSFTOKENIDCOMMON_H +#define ACCESSFTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accessftokenidcommon" + namespace OHOS { namespace Security { namespace AccessToken { -#define gettid() syscall(__NR_gettid) #define ACCESS_TOKEN_ID_IOCTL_BASE 'A' #ifdef CMDERROR @@ -61,4 +65,6 @@ int AccessfTokenidGrpTest(unsigned long long *data_ftoken); int AccessfTokenidGrpTestOther(unsigned long long *data_ftoken); } // namespace AccessToken } // namespace Security -} // namespace OHOS \ No newline at end of file +} // namespace OHOS + +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcommon.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h index 7f63066..24ca969 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcommon.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -13,10 +13,14 @@ * limitations under the License. */ +#ifndef ACCESSTOKENIDCOMMON_H +#define ACCESSTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accesstokenidcommon" + namespace OHOS { namespace Security { namespace AccessToken { -#define gettid() syscall(__NR_gettid) #define ACCESS_TOKEN_ID_IOCTL_BASE 'A' #ifdef CMDERROR @@ -62,3 +66,5 @@ int AccessTokenidGrpTestOther(unsigned long long *data_token); } // namespace AccessToken } // namespace Security } // namespace OHOS + +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp index 23caa80..494588b 100644 --- a/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -116,29 +116,29 @@ void ShowCurfToken() void SetRandfTokenAndCheck(unsigned long long *data_ftoken) { pid_t pid = getpid(); - pid_t tid = gettid(); + pid_t tid = syscall(__NR_gettid); unsigned long long ftoken = INVAL_TOKEN; unsigned long long ftokenSet = *data_ftoken; SetfTokenid(&ftokenSet); GetfTokenid(&ftoken); if (ftoken != ftokenSet) { - printf("pid:%d tid:%d ftoken test failed, ftoken:%#llx ftokenSet:%#llx\n", - pid, tid, ftoken, ftokenSet); + printf("pid:%d tid:%d ftoken test failed, ftoken:%#llu ftokenSet:%#llu\n", + pid, tid, ftoken, ftokenSet); } else { - printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llx ftokenSet:%#llx\n", - pid, tid, ftoken, ftokenSet); + printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llu ftokenSet:%#llu\n", + pid, tid, ftoken, ftokenSet); } sleep(WAIT_FOR_SHELL_OP_TIME); GetfTokenid(&ftoken); if (ftoken != ftokenSet) { - printf("pid:%d tid:%d ftoken test failed, ftoken:%#llx ftokenSet:%#llx\n", - pid, tid, ftoken, ftokenSet); + printf("pid:%d tid:%d ftoken test failed, ftoken:%#llu ftokenSet:%#llu\n", + pid, tid, ftoken, ftokenSet); } else { - printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llx ftokenSet:%#llx\n", - pid, tid, ftoken, ftokenSet); + printf("pid:%d tid:%d ftoken test succeed, ftoken:%#llu ftokenSet:%#llu\n", + pid, tid, ftoken, ftokenSet); } return; } @@ -160,27 +160,24 @@ void ThreadTest(void *data_ftoken) pthread_t id_3; int ret = 0; - ret = pthread_create(&id_1, NULL, fTokenTest, data_ftoken); - if(ret != 0) - { + ret = pthread_create(&id_1, nullptr, fTokenTest, data_ftoken); + if(ret != 0) { return; } - ret = pthread_create(&id_2, NULL, fTokenTest, data_ftoken); - if(ret != 0) - { + ret = pthread_create(&id_2, nullptr, fTokenTest, data_ftoken); + if(ret != 0) { return; } - ret = pthread_create(&id_3, NULL, fTokenTest, data_ftoken); - if(ret != 0) - { + ret = pthread_create(&id_3, nullptr, fTokenTest, data_ftoken); + if(ret != 0) { return; } - pthread_join(id_1, NULL); - pthread_join(id_2, NULL); - pthread_join(id_3, NULL); + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); return; } diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp index ead23fc..5523aff 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -112,7 +112,7 @@ void ShowCurToken() void SetRandTokenAndCheck(unsigned long long *data_token) { pid_t pid = getpid(); - pid_t tid = gettid(); + pid_t tid = syscall(__NR_gettid); unsigned long long token = INVAL_TOKEN; unsigned long long tokenSet = *data_token; SetTokenid(&tokenSet); @@ -120,22 +120,22 @@ void SetRandTokenAndCheck(unsigned long long *data_token) GetTokenid(&token); if (token != tokenSet) { - printf("pid:%d tid:%d token test failed, token:%#llx tokenSet:%#llx\n", - pid, tid, token, tokenSet); + printf("pid:%d tid:%d token test failed, token:%#llu tokenSet:%#llu\n", + pid, tid, token, tokenSet); } else { - printf("pid:%d tid:%d token test succeed, token:%#llx tokenSet:%#llx\n", - pid, tid, token, tokenSet); + printf("pid:%d tid:%d token test succeed, token:%#llu tokenSet:%#llu\n", + pid, tid, token, tokenSet); } sleep(WAIT_FOR_SHELL_OP_TIME); GetTokenid(&token); if (token != tokenSet) { - printf("pid:%d tid:%d token test failed, token:%#llx tokenSet:%#llx\n", - pid, tid, token, tokenSet); + printf("pid:%d tid:%d token test failed, token:%#llu tokenSet:%#llu\n", + pid, tid, token, tokenSet); } else { - printf("pid:%d tid:%d token test succeed, token:%#llx tokenSet:%#llx\n", - pid, tid, token, tokenSet); + printf("pid:%d tid:%d token test succeed, token:%#llu tokenSet:%#llu\n", + pid, tid, token, tokenSet); } return; } @@ -158,27 +158,24 @@ void ThreadTest(void *data_token) pthread_t id_3; int ret = 0; - ret = pthread_create(&id_1, NULL, TokenTest, data_token); - if(ret != 0) - { + ret = pthread_create(&id_1, nullptr, TokenTest, data_token); + if(ret != 0) { return; } - ret = pthread_create(&id_2, NULL, TokenTest, data_token); - if(ret != 0) - { + ret = pthread_create(&id_2, nullptr, TokenTest, data_token); + if(ret != 0) { return; } - ret = pthread_create(&id_3, NULL, TokenTest, data_token); - if(ret != 0) - { + ret = pthread_create(&id_3, nullptr, TokenTest, data_token); + if(ret != 0) { return; } - pthread_join(id_1, NULL); - pthread_join(id_2, NULL); - pthread_join(id_3, NULL); + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); return; } -- Gitee From 6aa977736341fdaad2c915d8efa618cbc17cb38e Mon Sep 17 00:00:00 2001 From: yang_mingdi Date: Tue, 31 May 2022 14:10:18 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accessftokenidgrptest_fuzzer.cpp | 2 +- .../accessftokenidgrptestother_fuzzer.cpp | 2 +- .../accessftokenidthreadtest_fuzzer.cpp | 2 +- .../accesstokenidgrptest_fuzzer.cpp | 2 +- .../accesstokenidgrptestother_fuzzer.cpp | 2 +- .../accesstokenidthreadtest_fuzzer.cpp | 2 +- .../getftokenidcmdcorrect_fuzzer.cpp | 2 +- .../getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp | 2 +- .../getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp | 2 +- .../gettokenidcmdcorrect_fuzzer.cpp | 2 +- .../gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp | 2 +- .../gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp | 2 +- test/fuzztest/accesstokenid/include/accessftokenidcommon.h | 4 ++-- test/fuzztest/accesstokenid/include/accesstokenidcommon.h | 4 ++-- .../setftokenidcmdcorrect_fuzzer.cpp | 2 +- .../setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp | 2 +- .../setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp | 2 +- .../settokenidcmdcorrect_fuzzer.cpp | 2 +- .../settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp | 2 +- .../settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp | 2 +- test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp | 4 ++-- test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp | 4 ++-- 22 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp index 4b5ff41..a5a0b8d 100644 --- a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessfTokenidGrpTestFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp index ab3d4a5..e2ce47f 100644 --- a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessfTokenidGrpTestOtherFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp index e08e1cc..d17ef3e 100644 --- a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessfTokenidThreadTestFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp index c3ef6ec..cc94691 100644 --- a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessTokenidGrpTestFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp index df37658..1d7a65c 100644 --- a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessTokenidGrpTestOtherFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp index e96bb79..1ce0823 100644 --- a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool AccessTokenidThreadTestFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp index be0a7a5..1173bb9 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp index 6bdc1d0..0ffb6a9 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -18,7 +18,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp index 00ab34c..c098598 100644 --- a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp index 22e9cdc..40762c2 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp index 606dceb..46d305e 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -18,7 +18,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp index 3acf32e..5be434e 100644 --- a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/include/accessftokenidcommon.h b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h index 00d54e4..51ab80f 100644 --- a/test/fuzztest/accesstokenid/include/accessftokenidcommon.h +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -19,7 +19,7 @@ #define FUZZ_PROJECT_NAME "accessftokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { #define ACCESS_TOKEN_ID_IOCTL_BASE 'A' @@ -64,7 +64,7 @@ int AccessfTokenidThreadTest(unsigned long long *data_ftoken); int AccessfTokenidGrpTest(unsigned long long *data_ftoken); int AccessfTokenidGrpTestOther(unsigned long long *data_ftoken); } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS #endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcommon.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h index 24ca969..2b31e8c 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcommon.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -19,7 +19,7 @@ #define FUZZ_PROJECT_NAME "accesstokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { #define ACCESS_TOKEN_ID_IOCTL_BASE 'A' @@ -64,7 +64,7 @@ int AccessTokenidThreadTest(unsigned long long *data_token); int AccessTokenidGrpTest(unsigned long long *data_token); int AccessTokenidGrpTestOther(unsigned long long *data_token); } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS #endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp index ae8f76e..000316c 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -17,7 +17,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp index a54f213..9a2f085 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -18,7 +18,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetfTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp index b1f84cb..f79706f 100644 --- a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp index a090a6a..7183f67 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp index c6b7d1d..37851e0 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -18,7 +18,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp index cceb0a8..715454c 100644 --- a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp @@ -19,7 +19,7 @@ #include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp index 494588b..dcaec88 100644 --- a/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -25,7 +25,7 @@ #include "accessftokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; @@ -205,5 +205,5 @@ int AccessfTokenidGrpTestOther(unsigned long long *data_ftoken) return 0; } } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp index 5523aff..c4dd1b6 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -25,7 +25,7 @@ #include "accesstokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; @@ -203,5 +203,5 @@ int AccessTokenidGrpTestOther(unsigned long long *data_token) return 0; } } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS -- Gitee From 9950a95ad2a726e49d674fd3e9c645139cd17317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=87=A1?= Date: Tue, 31 May 2022 06:34:24 +0000 Subject: [PATCH 10/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/accesstokenidcmdcorrect.cpp | 106 ------------------ 1 file changed, 106 deletions(-) delete mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp deleted file mode 100644 index 808820a..0000000 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 -- Gitee From cdba71776cc2d76539d5d02b87e98a58202add75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=87=A1?= Date: Tue, 31 May 2022 06:34:29 +0000 Subject: [PATCH 11/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/accesstokenidcmderror.cpp | 106 ------------------ 1 file changed, 106 deletions(-) delete mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp deleted file mode 100644 index f840f90..0000000 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 -- Gitee From 4f8869f94a5af558dab50cb1f1bb610ded4f55a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=87=A1?= Date: Tue, 31 May 2022 06:34:59 +0000 Subject: [PATCH 12/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/accesstokenidcmdcorrect.h | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h deleted file mode 100644 index d626a76..0000000 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -- Gitee From 38072dc6245d17580167eb67d4d22db986feb689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=87=A1?= Date: Tue, 31 May 2022 06:35:07 +0000 Subject: [PATCH 13/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/accesstokenid/include/accesstokenidcmderror.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/accesstokenidcmderror.h | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmderror.h diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h b/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h deleted file mode 100644 index 0ce6f09..0000000 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 -- Gitee