From a5000c96220edb1fea445359d89830c75872c27e Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 13 May 2022 10:09:00 +0800 Subject: [PATCH 1/3] cwm_0513_fuzztest Signed-off-by: cc_ggboy --- bundle.json | 9 ++- .../getdefpermission_fuzzer/BUILD.gn | 57 ++++++++++++++++++ .../getdefpermission_fuzzer/corpus/init | 14 +++++ .../getdefpermission_fuzzer.cpp | 60 +++++++++++++++++++ .../getdefpermission_fuzzer.h | 21 +++++++ .../getdefpermission_fuzzer/project.xml | 25 ++++++++ .../getpermissionflags_fuzzer/BUILD.gn | 57 ++++++++++++++++++ .../getpermissionflags_fuzzer/corpus/init | 14 +++++ .../getpermissionflags_fuzzer.cpp | 48 +++++++++++++++ .../getpermissionflags_fuzzer.h | 21 +++++++ .../getpermissionflags_fuzzer/project.xml | 25 ++++++++ .../grantpermission_fuzzer/BUILD.gn | 57 ++++++++++++++++++ .../grantpermission_fuzzer/corpus/init | 14 +++++ .../grantpermission_fuzzer.cpp | 48 +++++++++++++++ .../grantpermission_fuzzer.h | 21 +++++++ .../grantpermission_fuzzer/project.xml | 25 ++++++++ .../BUILD.gn | 57 ++++++++++++++++++ .../corpus/init | 14 +++++ .../project.xml | 25 ++++++++ .../revokeusergrantedpermission_fuzzer.cpp | 48 +++++++++++++++ .../revokeusergrantedpermission_fuzzer.h | 21 +++++++ .../verifyaccesstoken_fuzzer/BUILD.gn | 57 ++++++++++++++++++ .../verifyaccesstoken_fuzzer/corpus/init | 14 +++++ .../verifyaccesstoken_fuzzer/project.xml | 25 ++++++++ .../verifyaccesstoken_fuzzer.cpp | 48 +++++++++++++++ .../verifyaccesstoken_fuzzer.h | 21 +++++++ 26 files changed, 844 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp create mode 100644 test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h create mode 100644 test/fuzztest/access_token/getdefpermission_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp create mode 100644 test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h create mode 100644 test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/grantpermission_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp create mode 100644 test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h create mode 100644 test/fuzztest/access_token/grantpermission_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp create mode 100644 test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h create mode 100644 test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp create mode 100644 test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h diff --git a/bundle.json b/bundle.json index 5407eee17..462bda7bb 100644 --- a/bundle.json +++ b/bundle.json @@ -79,8 +79,13 @@ "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", - "//base/security/access_token/interfaces/kits/accesstoken/test/benchmarktest:benchmarktest" + "//base/security/access_token/interfaces/kits/accesstoken/test/benchmarktest:benchmarktest", + "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_fuzzer:fuzztest", + "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer:fuzztest", + "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_fuzzer:fuzztest", + "//base/security/access_token/test/fuzztest/access_token/grantpermission_fuzzer:fuzztest", + "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer:fuzztest" ] } } -} +} \ No newline at end of file diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn new file mode 100644 index 000000000..70ab045e4 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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 = "access_token/access_token" + +ohos_fuzztest("GetDefPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/frameworks/common/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getdefpermission_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GetDefPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init b/test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp new file mode 100644 index 000000000..6d0186eb1 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "getdefpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" +#include "permission_def.h" + +using namespace std; +using namespace OHOS; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool GetDefPermissionFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + PermissionDef PERMISSIONDEF = { + .permissionName = "ohos.permission.test1", + .bundleName = "accesstoken_test", + .grantMode = 1, + .label = "label", + .labelId = 1, + .description = "open the door", + .availableLevel = APL_NORMAL, + .descriptionId = 1 + }; + result = AccessTokenKit::GetDefPermission(reinterpret_cast(data), PERMISSIONDEF); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetDefPermissionFuzzTest(data, size); + return 0; +} + \ No newline at end of file diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h new file mode 100644 index 000000000..5d8983a59 --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETDEFPERMISSION_FUZZER_H +#define TEST_FUZZTEST_GETDEFPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "getdefpermission_fuzzer" + +#endif // TEST_FUZZTEST_GETDEFPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml b/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn new file mode 100644 index 000000000..a8357377b --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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 = "access_token/access_token" + +ohos_fuzztest("GetPermissionFlagsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getpermissionflags_fuzzer.cpp" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GetPermissionFlagsFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init b/test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp new file mode 100644 index 000000000..f90af5f15 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "getpermissionflags_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +AccessTokenID TOKENID = 1; + +namespace OHOS { + bool GetPermissionFlagsFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::GetPermissionFlag(TOKENID, reinterpret_cast(data)); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GetPermissionFlagsFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h new file mode 100644 index 000000000..8d7b1d347 --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GETPERMISSIONFLAGS_FUZZER_H +#define TEST_FUZZTEST_GETPERMISSIONFLAGS_FUZZER_H + +#define FUZZ_PROJECT_NAME "getpermissionflags_fuzzer" + +#endif // TEST_FUZZTEST_GETPERMISSIONFLAGS_FUZZER_H diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml b/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn new file mode 100644 index 000000000..a62ffa945 --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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 = "access_token/access_token" + +ohos_fuzztest("GrantPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/security/access_token/test/fuzztest/access_token/grantpermission_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "grantpermission_fuzzer.cpp" ] + + deps = [ + "//utils/native/base:utils", + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":GrantPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/corpus/init b/test/fuzztest/access_token/grantpermission_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp new file mode 100644 index 000000000..ee80bad4a --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "grantpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +AccessTokenID TOKENID = 1; + +namespace OHOS { + bool GrantPermissionFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::GrantPermission(TOKENID, reinterpret_cast(data), 0); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::GrantPermissionFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h new file mode 100644 index 000000000..64a6c5498 --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GRANTPERMISSION_FUZZER_H +#define TEST_FUZZTEST_GRANTPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "grantpermission_fuzzer" + +#endif // TEST_FUZZTEST_GRANTPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/project.xml b/test/fuzztest/access_token/grantpermission_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/grantpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn new file mode 100644 index 000000000..d4698bac3 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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 = "access_token/access_token" + +ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "revokeusergrantedpermission_fuzzer.cpp" ] + + deps = [ + "//utils/native/base:utils", + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":RevokeUserGrantedPermissionFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp new file mode 100644 index 000000000..3e93e2734 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "revokeusergrantedpermission_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +AccessTokenID TOKENID = 1; + +namespace OHOS { + bool RevokeUserGrantedPermissionFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::RevokePermission(TOKENID, reinterpret_cast(data), 0); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::RevokeUserGrantedPermissionFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h new file mode 100644 index 000000000..3324007c9 --- /dev/null +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REVOKEUSERGRANTEDPERMISSION_FUZZER_H +#define TEST_FUZZTEST_REVOKEUSERGRANTEDPERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "revokeusergrantedpermission_fuzzer" + +#endif // TEST_FUZZTEST_REVOKEUSERGRANTEDPERMISSION_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn new file mode 100644 index 000000000..e629ed645 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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 = "access_token/access_token" + +ohos_fuzztest("VerifyAccessTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "verifyaccesstoken_fuzzer.cpp" ] + + deps = [ + "//utils/native/base:utils", + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + + defines = [ + "ACCOUNT_LOG_TAG = \"AccessTokenFuzzTest\"", + "LOG_DOMAIN = 0xD001B00", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":VerifyAccessTokenFuzzTest", + ] +} diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp new file mode 100644 index 000000000..8f956aee9 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * 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 "verifyaccesstoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +AccessTokenID TOKENID = 1; + +namespace OHOS { + bool VerifyAccessTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::VerifyAccessToken(TOKENID, reinterpret_cast(data)); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::VerifyAccessTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h new file mode 100644 index 000000000..c754140f2 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_VERIFYACCESSTOKEN_FUZZER_H +#define TEST_FUZZTEST_VERIFYACCESSTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "verifyaccesstoken_fuzzer" + +#endif // TEST_FUZZTEST_VERIFYACCESSTOKEN_FUZZER_H -- Gitee From b52e6b15d142860dd370e3fd858bc5291e350b62 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 13 May 2022 11:23:36 +0800 Subject: [PATCH 2/3] cwm_0513_fuzztest Signed-off-by: cc_ggboy --- .../access_token/getdefpermission_fuzzer/BUILD.gn | 7 +++---- .../getdefpermission_fuzzer/getdefpermission_fuzzer.cpp | 8 ++++---- .../access_token/getpermissionflags_fuzzer/BUILD.gn | 7 +++---- .../getpermissionflags_fuzzer.cpp | 2 +- .../access_token/grantpermission_fuzzer/BUILD.gn | 9 ++++----- .../grantpermission_fuzzer/grantpermission_fuzzer.cpp | 2 +- .../revokeusergrantedpermission_fuzzer/BUILD.gn | 9 ++++----- .../revokeusergrantedpermission_fuzzer.cpp | 2 +- .../access_token/verifyaccesstoken_fuzzer/BUILD.gn | 9 ++++----- .../verifyaccesstoken_fuzzer.cpp | 2 +- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn index 70ab045e4..92743d205 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn @@ -18,9 +18,8 @@ module_output_path = "access_token/access_token" ohos_fuzztest("GetDefPermissionFuzzTest") { module_out_path = module_output_path - fuzz_config_file = - "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer" - + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/getdefpermission_fuzzer" + include_dirs = [ "//utils/native/base/include", "//base/security/access_token/frameworks/common/include", @@ -49,7 +48,7 @@ ohos_fuzztest("GetDefPermissionFuzzTest") { group("fuzztest") { testonly = true deps = [] - + deps += [ # deps file ":GetDefPermissionFuzzTest", diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp index 6d0186eb1..aa3218083 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp @@ -35,12 +35,12 @@ namespace OHOS { } if (size > 0) { PermissionDef PERMISSIONDEF = { - .permissionName = "ohos.permission.test1", - .bundleName = "accesstoken_test", + .permissionName = reinterpret_cast(data), + .bundleName = reinterpret_cast(data), .grantMode = 1, - .label = "label", + .label = reinterpret_cast(data), .labelId = 1, - .description = "open the door", + .description = reinterpret_cast(data), .availableLevel = APL_NORMAL, .descriptionId = 1 }; diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn index a8357377b..9a70902d0 100644 --- a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn @@ -18,9 +18,8 @@ module_output_path = "access_token/access_token" ohos_fuzztest("GetPermissionFlagsFuzzTest") { module_out_path = module_output_path - fuzz_config_file = - "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_fuzzer" - + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/getpermissionflags_fuzzer" + include_dirs = [ "//utils/native/base/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", @@ -49,7 +48,7 @@ ohos_fuzztest("GetPermissionFlagsFuzzTest") { group("fuzztest") { testonly = true deps = [] - + deps += [ # deps file ":GetPermissionFlagsFuzzTest", diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp index f90af5f15..be7739e64 100644 --- a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp @@ -23,7 +23,6 @@ using namespace std; using namespace OHOS::Security::AccessToken; -AccessTokenID TOKENID = 1; namespace OHOS { bool GetPermissionFlagsFuzzTest(const uint8_t* data, size_t size) @@ -33,6 +32,7 @@ namespace OHOS { return result; } if (size > 0) { + AccessTokenID TOKENID = 1; result = AccessTokenKit::GetPermissionFlag(TOKENID, reinterpret_cast(data)); } return result; diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn index a62ffa945..987aa46ac 100644 --- a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn @@ -18,9 +18,8 @@ module_output_path = "access_token/access_token" ohos_fuzztest("GrantPermissionFuzzTest") { module_out_path = module_output_path - fuzz_config_file = - "//base/security/access_token/test/fuzztest/access_token/grantpermission_fuzzer" - + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/grantpermission_fuzzer" + include_dirs = [ "//utils/native/base/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", @@ -34,8 +33,8 @@ ohos_fuzztest("GrantPermissionFuzzTest") { sources = [ "grantpermission_fuzzer.cpp" ] deps = [ - "//utils/native/base:utils", "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -49,7 +48,7 @@ ohos_fuzztest("GrantPermissionFuzzTest") { group("fuzztest") { testonly = true deps = [] - + deps += [ # deps file ":GrantPermissionFuzzTest", diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp index ee80bad4a..c8da140fa 100644 --- a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp @@ -23,7 +23,6 @@ using namespace std; using namespace OHOS::Security::AccessToken; -AccessTokenID TOKENID = 1; namespace OHOS { bool GrantPermissionFuzzTest(const uint8_t* data, size_t size) @@ -33,6 +32,7 @@ namespace OHOS { return result; } if (size > 0) { + AccessTokenID TOKENID = 1; result = AccessTokenKit::GrantPermission(TOKENID, reinterpret_cast(data), 0); } return result; diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn index d4698bac3..ba5d208a1 100644 --- a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn @@ -18,9 +18,8 @@ module_output_path = "access_token/access_token" ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { module_out_path = module_output_path - fuzz_config_file = - "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer" - + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer" + include_dirs = [ "//utils/native/base/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", @@ -34,8 +33,8 @@ ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { sources = [ "revokeusergrantedpermission_fuzzer.cpp" ] deps = [ - "//utils/native/base:utils", "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -49,7 +48,7 @@ ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { group("fuzztest") { testonly = true deps = [] - + deps += [ # deps file ":RevokeUserGrantedPermissionFuzzTest", diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp index 3e93e2734..34558a8f8 100644 --- a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp @@ -23,7 +23,6 @@ using namespace std; using namespace OHOS::Security::AccessToken; -AccessTokenID TOKENID = 1; namespace OHOS { bool RevokeUserGrantedPermissionFuzzTest(const uint8_t* data, size_t size) @@ -33,6 +32,7 @@ namespace OHOS { return result; } if (size > 0) { + AccessTokenID TOKENID = 1; result = AccessTokenKit::RevokePermission(TOKENID, reinterpret_cast(data), 0); } return result; diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn index e629ed645..3357958b6 100644 --- a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn @@ -18,9 +18,8 @@ module_output_path = "access_token/access_token" ohos_fuzztest("VerifyAccessTokenFuzzTest") { module_out_path = module_output_path - fuzz_config_file = - "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_fuzzer" - + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken_fuzzer" + include_dirs = [ "//utils/native/base/include", "//base/security/access_token/interfaces/innerkits/accesstoken/include", @@ -34,8 +33,8 @@ ohos_fuzztest("VerifyAccessTokenFuzzTest") { sources = [ "verifyaccesstoken_fuzzer.cpp" ] deps = [ - "//utils/native/base:utils", "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//utils/native/base:utils", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -49,7 +48,7 @@ ohos_fuzztest("VerifyAccessTokenFuzzTest") { group("fuzztest") { testonly = true deps = [] - + deps += [ # deps file ":VerifyAccessTokenFuzzTest", diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp index 8f956aee9..60343afff 100644 --- a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp @@ -23,7 +23,6 @@ using namespace std; using namespace OHOS::Security::AccessToken; -AccessTokenID TOKENID = 1; namespace OHOS { bool VerifyAccessTokenFuzzTest(const uint8_t* data, size_t size) @@ -33,6 +32,7 @@ namespace OHOS { return result; } if (size > 0) { + AccessTokenID TOKENID = 1; result = AccessTokenKit::VerifyAccessToken(TOKENID, reinterpret_cast(data)); } return result; -- Gitee From 9cca56336b77b26d9b6fdf2cf700564291b4033d Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 13 May 2022 15:42:28 +0800 Subject: [PATCH 3/3] cwm_0513_fuzztest Signed-off-by: cc_ggboy --- .../getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp | 2 +- .../grantpermission_fuzzer/grantpermission_fuzzer.cpp | 2 +- .../revokeusergrantedpermission_fuzzer.cpp | 2 +- .../verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp index be7739e64..9175d62dd 100644 --- a/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/getpermissionflags_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { return result; } if (size > 0) { - AccessTokenID TOKENID = 1; + AccessTokenID TOKENID = static_cast(size); result = AccessTokenKit::GetPermissionFlag(TOKENID, reinterpret_cast(data)); } return result; diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp index c8da140fa..b821ba974 100644 --- a/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/grantpermission_fuzzer/grantpermission_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { return result; } if (size > 0) { - AccessTokenID TOKENID = 1; + AccessTokenID TOKENID = static_cast(size); result = AccessTokenKit::GrantPermission(TOKENID, reinterpret_cast(data), 0); } return result; diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp index 34558a8f8..c2a1dc550 100644 --- a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/revokeusergrantedpermission_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { return result; } if (size > 0) { - AccessTokenID TOKENID = 1; + AccessTokenID TOKENID = static_cast(size); result = AccessTokenKit::RevokePermission(TOKENID, reinterpret_cast(data), 0); } return result; diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp index 60343afff..de192b189 100644 --- a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/verifyaccesstoken_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { return result; } if (size > 0) { - AccessTokenID TOKENID = 1; + AccessTokenID TOKENID = static_cast(size); result = AccessTokenKit::VerifyAccessToken(TOKENID, reinterpret_cast(data)); } return result; -- Gitee