From 829bfe7617c2cdb749665342ad653a18ac97f1fb Mon Sep 17 00:00:00 2001 From: wenfei Date: Mon, 30 May 2022 19:45:32 +0800 Subject: [PATCH] add access_to_ken_id new dtfuzzer testcase Signed-off-by: wenfei --- 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 | 5 +- .../getftokenidcmderror_fuzzer/BUILD.gn | 2 +- .../getftokenidcmderror_fuzzer.cpp | 6 +- .../getftokenidnullptr_fuzzer/BUILD.gn | 42 ++++ .../getftokenidnullptr_fuzzer/corpus/init | 14 ++ .../getftokenidnullptr_fuzzer.cpp | 41 ++++ .../getftokenidnullptr_fuzzer/project.xml | 25 +++ .../gettokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../gettokenidcmdcorrect_fuzzer.cpp | 5 +- .../gettokenidcmderror_fuzzer/BUILD.gn | 2 +- .../gettokenidcmderror_fuzzer.cpp | 6 +- .../gettokenidnullptr_fuzzer/BUILD.gn | 42 ++++ .../gettokenidnullptr_fuzzer/corpus/init | 14 ++ .../gettokenidnullptr_fuzzer.cpp | 41 ++++ .../gettokenidnullptr_fuzzer/project.xml | 25 +++ .../include/accessftokenidcommon.h | 70 +++++++ .../include/accesstokenidcmdcorrect.h | 44 ---- .../include/accesstokenidcmderror.h | 44 ---- .../include/accesstokenidcommon.h | 70 +++++++ .../setftokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../setftokenidcmdcorrect_fuzzer.cpp | 5 +- .../setftokenidcmderror_fuzzer/BUILD.gn | 2 +- .../setftokenidcmderror_fuzzer.cpp | 6 +- .../setftokenidnullptr_fuzzer/BUILD.gn | 42 ++++ .../setftokenidnullptr_fuzzer/corpus/init | 14 ++ .../setftokenidnullptr_fuzzer/project.xml | 25 +++ .../setftokenidnullptr_fuzzer.cpp | 41 ++++ .../settokenidcmdcorrect_fuzzer/BUILD.gn | 2 +- .../settokenidcmdcorrect_fuzzer.cpp | 5 +- .../settokenidcmderror_fuzzer/BUILD.gn | 2 +- .../settokenidcmderror_fuzzer.cpp | 6 +- .../settokenidnullptr_fuzzer/BUILD.gn | 42 ++++ .../settokenidnullptr_fuzzer/corpus/init | 14 ++ .../settokenidnullptr_fuzzer/project.xml | 25 +++ .../settokenidnullptr_fuzzer.cpp | 41 ++++ .../src/accessftokenidcommon.cpp | 195 ++++++++++++++++++ .../src/accesstokenidcmdcorrect.cpp | 106 ---------- .../src/accesstokenidcmderror.cpp | 106 ---------- .../accesstokenid/src/accesstokenidcommon.cpp | 192 +++++++++++++++++ 65 files changed, 1779 insertions(+), 332 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 create mode 100644 test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp 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 create mode 100644 test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml create mode 100644 test/fuzztest/accesstokenid/include/accessftokenidcommon.h delete mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h delete mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcmderror.h create mode 100644 test/fuzztest/accesstokenid/include/accesstokenidcommon.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 create mode 100644 test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp 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 create mode 100644 test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp create mode 100644 test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp delete mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp delete mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp create mode 100644 test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp 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..c535b27 --- /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::Kernel::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 { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidGrpTest(data_ftoken); + } + 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..399d77f --- /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::Kernel::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 { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidGrpTestOther(data_ftoken); + } + 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..4212980 --- /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::Kernel::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 { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidThreadTest(data_ftoken); + } + 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..af5b636 --- /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::Kernel::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 { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidGrpTest(data_token); + } + 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..a4e57da --- /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::Kernel::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 { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidGrpTestOther(data_token); + } + 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..5215747 --- /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::Kernel::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 { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidThreadTest(data_token); + } + 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..1173bb9 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -14,11 +14,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "getftokenidcmdcorrect_fuzzer.h" +#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/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..0ffb6a9 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "getftokenidcmderror_fuzzer.h" +#define CMDERROR +#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/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/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000..c098598 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + reinterpret_cast + static_cast + */ + +#include +#include "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::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; +} +} + +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..40762c2 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -16,11 +16,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "gettokenidcmdcorrect_fuzzer.h" +#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/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..46d305e 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "gettokenidcmderror_fuzzer.h" +#define CMDERROR +#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/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/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000..5be434e --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::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; +} +} + +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/accessftokenidcommon.h b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h new file mode 100644 index 0000000..e0c3903 --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -0,0 +1,70 @@ +/* + * 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 ACCESSFTOKENIDCOMMON_H +#define ACCESSFTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accessftokenidcommon" + +namespace OHOS { +namespace Kernel { +namespace AccessToken { +#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) + +#define LIST_NUM_1 1 +#define LIST_NUM_2 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 SetRandfTokenAndCheck(unsigned long long *data_ftoken); +void fTokenTest(unsigned long long *data_ftoken); +void ThreadTest(unsigned long long *data_ftoken); +int AccessfTokenidThreadTest(uint8_t *data_ftoken); +int AccessfTokenidGrpTest(uint8_t *data_ftoken); +int AccessfTokenidGrpTestOther(uint8_t *data_ftoken); +} // namespace AccessToken +} // namespace Kernel +} // namespace OHOS + +#endif // ACCESSTOKENIDCOMMON_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 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 diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcommon.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h new file mode 100644 index 0000000..febe475 --- /dev/null +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -0,0 +1,70 @@ +/* + * 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 ACCESSTOKENIDCOMMON_H +#define ACCESSTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accesstokenidcommon" + +namespace OHOS { +namespace Kernel { +namespace AccessToken { +#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 LIST_NUM_1 1 +#define LIST_NUM_2 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 SetRandTokenAndCheck(unsigned long long *data_token); +void TokenTest(unsigned long long *data_token); +void ThreadTest(unsigned long long *data_token); +int AccessTokenidThreadTest(uint8_t *data_token); +int AccessTokenidGrpTest(uint8_t *data_token); +int AccessTokenidGrpTestOther(uint8_t *data_token); +} // namespace AccessToken +} // namespace Kernel +} // namespace OHOS + +#endif // ACCESSTOKENIDCOMMON_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..000316c 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -14,11 +14,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "setftokenidcmdcorrect_fuzzer.h" +#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/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..9a2f085 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "setftokenidcmderror_fuzzer.h" +#define CMDERROR +#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/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/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000..f79706f --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + reinterpret_cast + static_cast + */ + +#include +#include "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::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; +} +} + +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..7183f67 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -16,11 +16,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "settokenidcmdcorrect_fuzzer.h" +#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/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..37851e0 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "settokenidcmderror_fuzzer.h" +#define CMDERROR +#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/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/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000..715454c --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::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; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp new file mode 100644 index 0000000..6fa504f --- /dev/null +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -0,0 +1,195 @@ +/* + * 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 "accessftokenidcommon.h" + +namespace OHOS { +namespace Kernel { +namespace AccessToken { +const char *DEVACCESSTOKENID = "/dev/access_token_id"; + +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; +} + +void SetUidAndGrp() +{ + int ret = 0; + size_t groupListSize = LIST_NUM_2; + gid_t groupList[LIST_NUM_2] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; + } + + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); + } + + return; +} + +void SetUidAndGrpOther() +{ + int ret = 0; + size_t groupListSize = LIST_NUM_1; + gid_t groupList[LIST_NUM_1] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; + } + + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \r\n", ret); + } + + return; +} + +void SetRandfTokenAndCheck(unsigned long long *data_ftoken) +{ + pid_t pid = getpid(); + 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:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } else { + 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:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } else { + printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } + return; +} + +void *fTokenTest(void *data_ftoken) +{ + SetRandfTokenAndCheck(static_cast(data_ftoken)); + return nullptr; +} + +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, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_2, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_3, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); + + return; +} + +int AccessfTokenidThreadTest(uint8_t *data_ftoken) +{ + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTest(uint8_t *data_ftoken) +{ + SetUidAndGrp(); + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTestOther(uint8_t *data_ftoken) +{ + SetUidAndGrpOther(); + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); + return 0; +} +} // namespace AccessToken +} // namespace Kernel +} // namespace OHOS 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 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 diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp new file mode 100644 index 0000000..1be96bd --- /dev/null +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -0,0 +1,192 @@ +/* + * 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 "accesstokenidcommon.h" + +namespace OHOS { +namespace Kernel { +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; +} + +void SetUidAndGrp() +{ + int ret = 0; + size_t groupListSize = LIST_NUM_2; + gid_t groupList[LIST_NUM_2] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; + } + + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); + } + + return; +} + +void SetUidAndGrpOther() +{ + int ret = 0; + size_t groupListSize = LIST_NUM_1; + gid_t groupList[LIST_NUM_1] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; + } + + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); + } + + return; +} + +void SetRandTokenAndCheck(unsigned long long *data_token) +{ + pid_t pid = getpid(); + pid_t tid = syscall(__NR_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:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } else { + 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:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } else { + printf("pid:%d tid:%d token test succeed, token:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } + return; +} + +void *TokenTest(void *data_token) +{ + SetRandTokenAndCheck(static_cast(data_token)); + + return nullptr; +} + +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, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_2, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_3, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); + + return; +} + +int AccessTokenidThreadTest(uint8_t *data_token) +{ + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTest(uint8_t *data_token) +{ + SetUidAndGrp(); + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTestOther(uint8_t *data_token) +{ + SetUidAndGrpOther(); + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); + return 0; +} +} // namespace AccessToken +} // namespace Kernel +} // namespace OHOS