diff --git a/test/fuzztest/accesstokenid/BUILD.gn b/test/fuzztest/accesstokenid/BUILD.gn index aa82ac29138f2ed60a1239d1232a9eaa9bc69169..a637feb54660c7322d939c0afbed7500ed8be72e 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 0000000000000000000000000000000000000000..25f6b34d81c1927d31763313f2c85b67c23ff139 --- /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 0000000000000000000000000000000000000000..c535b276f673a73131c438ea23a555b3ad9c7101 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..d902d27f417973e42fb0de63fcbba0f6935de5db --- /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 0000000000000000000000000000000000000000..399d77f49cbe2bf363a29dcd0d263dca7a206537 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..3bdbd2bbb40092340d484da3c7d6a22b3fc20c11 --- /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 0000000000000000000000000000000000000000..42129808f82758415c5ffa9c8ea2598935b30ae3 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..c83fa86a5714f101f41e5d274c2723a8f6430592 --- /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 0000000000000000000000000000000000000000..af5b63685345d7d0c4710b08fef1619c9126aa1c --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..a7ffa34d55318a36c3a22d83f1843a6adc381059 --- /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 0000000000000000000000000000000000000000..a4e57da17d3d51a68e837588583f6a8787f7a158 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..b643bcff5bbeb32309fe4657dd27eb5eefcebdd3 --- /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 0000000000000000000000000000000000000000..5215747069b19cdb0e76324df45db7f2572a293e --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 b9bbbf22c880cb2b72ef7e490e5380e5e796e505..dd833e2068a3286420d1f26f7a8c8193b5325c0f 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 fd0d5d7b609767cabf34c9b2d4266dcaa0d54173..1173bb9352a3a98c6b0d14b8ae7b24f1bcc6d030 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 fda5dce486cc0c21abc02b81afdbdad768e527db..66b1aab8178c3de7ab0ef03e7bc287ac00a9f719 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 235306a085b1123fbfde99e4bcbfea5d653f3b0c..0ffb6a996379b9cdb5d2c4dadd386f5e6ac5449d 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 0000000000000000000000000000000000000000..a7aa7278a55657d3651f13da66e2c3ac16bae9a8 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..c098598c96f64f3811bc60a111979a9425b9ac6b --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 51af0fd3a886087149b502f87a218194b80eccb0..1e8be2f58612f95347dedcdccd6db8728efa9334 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 9bee2a94697f33c9c9c3380b302cbbb48fc5a8f3..40762c219ab01753b52fd948f3be228ac15151a3 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 2131812419bbe780acfa9e41024a4bf6c2485506..d72acf87f2d142b5f0198ec16a2cc1715a00b99a 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 02242b6aa06d41e3785affcf69a78dc351c980e7..46d305e8b425f7fea67f3e039097e1eee3b68ace 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 0000000000000000000000000000000000000000..912b3bc126c31f0da32383ffca5d4431e69c985b --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..5be434efe3e662e364592d7f6f59f41af052354d --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 40% rename from test/fuzztest/accesstokenid/include/accesstokenidcmderror.h rename to test/fuzztest/accesstokenid/include/accessftokenidcommon.h index 0ce6f092984504ed5787955048c7658e31fa2cec..e0c3903814f6e5c8f8ac84ac8bca07d9c2629a5d 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -12,33 +12,59 @@ * 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 + +#ifndef ACCESSFTOKENIDCOMMON_H +#define ACCESSFTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accessftokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { 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_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_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 Security +} // namespace Kernel } // namespace OHOS -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h similarity index 41% rename from test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h rename to test/fuzztest/accesstokenid/include/accesstokenidcommon.h index d626a76af4567a79525a1cd148d858c74092baf9..febe47573e273447a4db1992012e962dc20b96d3 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -12,33 +12,59 @@ * 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 + +#ifndef ACCESSTOKENIDCOMMON_H +#define ACCESSTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accesstokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { 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_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_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 Security +} // namespace Kernel } // namespace OHOS -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn index 916f7dd7a8c75732815a022a7a65d794ce809426..bdabf6fa9cc37a6801b48d146972d4d2d402a90e 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 4fea69011c050efa51f4c8b5bb3d96396cf50859..000316cb94c492fd14bd3f28d4ad6a4eec791df3 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 f15c87ef9755482871769502570e3823c707e8ef..00fb0ffc6e165a7435d002b6b42a249fbe6b2e60 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 cce1d22623781e0a171fb18052e0b7f29d18d69c..9a2f08595bfa7f7e3631adc2caf37411d3e41e60 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 0000000000000000000000000000000000000000..0847e822561b035a429bf7825a397478c8662c93 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..f79706f091622994daa87c5cb3c927df2ae88a9c --- /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 f44747352a2f0d60041814d3b1a3ad5e41d58f92..0def8993e6dbb8ec81dd88b2fab223649facc454 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 602c55f41a692f0e5188f152e60f70e044739ee8..7183f678a1f862899d99c7c5ac411217b6267fc1 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 126f61fb147caa7a4f9be4efa8cd46870c12e897..037811e6c3e406eada1d9cbc06b647dc490c0fcf 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 fcb9cfa51ea012ca568ee8db2d1dae282256c81f..37851e069437b857a1c7dbf629b6adab8e8f5002 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 0000000000000000000000000000000000000000..3b78e95cd07fb79f8c5e3084f7ebcb60030eac67 --- /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 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..715454c97a7f05d5db7c2afaf7e9c978afb70878 --- /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/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp similarity index 34% rename from test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp rename to test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp index f840f90b96b9df575b94f0cccfcfe6637c5962b1..bf5a748fbdafaaa7b1adf5c996647a02027da28d 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -15,33 +15,29 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmderror.h" +#include +#include "accessftokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { 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 +47,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,39 +64,132 @@ 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_2] = {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[LIST_NUM_1] = {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 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 Security +} // namespace Kernel } // namespace OHOS diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp similarity index 35% rename from test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp rename to test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp index 808820ac3fef21cb612aee2807e1199a3833cea8..21c1cbc246f963a6a0b091f8ff7ae8019a008e5e 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -15,22 +15,18 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmdcorrect.h" +#include +#include "accesstokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; @@ -40,13 +36,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,50 +51,142 @@ 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_2] = {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[LIST_NUM_1] = {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 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 Security +} // namespace Kernel } // namespace OHOS