From 9434d8873b7350795ac134d35430b93014158ff1 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Tue, 17 May 2022 10:12:34 +0800 Subject: [PATCH 1/2] cwm_0517_fuzz Signed-off-by: cc_ggboy --- bundle.json | 6 +- test/fuzztest/access_token/BUILD.gn | 37 +++++++ .../allochaptoken_fuzzer/BUILD.gn | 46 ++++++++ .../allochaptoken_fuzzer.cpp | 101 ++++++++++++++++++ .../allochaptoken_fuzzer.h | 21 ++++ .../allochaptoken_fuzzer/corpus/init | 14 +++ .../allochaptoken_fuzzer/project.xml | 25 +++++ .../alloclocaltokenid_fuzzer/BUILD.gn | 46 ++++++++ .../alloclocaltokenid_fuzzer.cpp | 49 +++++++++ .../alloclocaltokenid_fuzzer.h | 21 ++++ .../alloclocaltokenid_fuzzer/corpus/init | 14 +++ .../alloclocaltokenid_fuzzer/project.xml | 25 +++++ .../checknativedcap_fuzzer/BUILD.gn | 46 ++++++++ .../checknativedcap_fuzzer.cpp | 48 +++++++++ .../checknativedcap_fuzzer.h | 21 ++++ .../checknativedcap_fuzzer/corpus/init | 14 +++ .../checknativedcap_fuzzer/project.xml | 25 +++++ .../BUILD.gn | 46 ++++++++ ...clearusergrantedpermissionstate_fuzzer.cpp | 48 +++++++++ .../clearusergrantedpermissionstate_fuzzer.h | 21 ++++ .../corpus/init | 14 +++ .../project.xml | 25 +++++ .../deleteremotedevicetokens_fuzzer/BUILD.gn | 46 ++++++++ .../corpus/init | 14 +++ .../deleteremotedevicetokens_fuzzer.cpp | 56 ++++++++++ .../deleteremotedevicetokens_fuzzer.h | 21 ++++ .../project.xml | 25 +++++ .../deleteremotetoken_fuzzer/BUILD.gn | 46 ++++++++ .../deleteremotetoken_fuzzer/corpus/init | 14 +++ .../deleteremotetoken_fuzzer.cpp | 57 ++++++++++ .../deleteremotetoken_fuzzer.h | 21 ++++ .../deleteremotetoken_fuzzer/project.xml | 25 +++++ .../access_token/deletetoken_fuzzer/BUILD.gn | 46 ++++++++ .../deletetoken_fuzzer/corpus/init | 14 +++ .../deletetoken_fuzzer/deletetoken_fuzzer.cpp | 48 +++++++++ .../deletetoken_fuzzer/deletetoken_fuzzer.h | 21 ++++ .../deletetoken_fuzzer/project.xml | 25 +++++ .../getdefpermission_fuzzer/BUILD.gn | 10 -- .../getdefpermission_fuzzer.cpp | 12 ++- .../getpermissionflags_fuzzer/BUILD.gn | 10 -- .../grantpermission_fuzzer/BUILD.gn | 10 -- .../BUILD.gn | 10 -- .../setremotehaptokeninfo_fuzzer/BUILD.gn | 46 ++++++++ .../setremotehaptokeninfo_fuzzer/corpus/init | 14 +++ .../setremotehaptokeninfo_fuzzer/project.xml | 25 +++++ .../setremotehaptokeninfo_fuzzer.cpp | 77 +++++++++++++ .../setremotehaptokeninfo_fuzzer.h | 21 ++++ .../setremotenativetokeninfo_fuzzer/BUILD.gn | 46 ++++++++ .../corpus/init | 14 +++ .../project.xml | 25 +++++ .../setremotenativetokeninfo_fuzzer.cpp | 69 ++++++++++++ .../setremotenativetokeninfo_fuzzer.h | 21 ++++ .../updatehaptoken_fuzzer/BUILD.gn | 46 ++++++++ .../updatehaptoken_fuzzer/corpus/init | 14 +++ .../updatehaptoken_fuzzer/project.xml | 25 +++++ .../updatehaptoken_fuzzer.cpp | 96 +++++++++++++++++ .../updatehaptoken_fuzzer.h | 21 ++++ .../verifyaccesstoken001_fuzzer/BUILD.gn | 46 ++++++++ .../verifyaccesstoken001_fuzzer/corpus/init | 14 +++ .../verifyaccesstoken001_fuzzer/project.xml | 25 +++++ .../verifyaccesstoken001_fuzzer.cpp | 48 +++++++++ .../verifyaccesstoken001_fuzzer.h | 21 ++++ .../verifyaccesstoken_fuzzer/BUILD.gn | 10 -- 63 files changed, 1908 insertions(+), 60 deletions(-) create mode 100644 test/fuzztest/access_token/BUILD.gn create mode 100644 test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp create mode 100644 test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h create mode 100644 test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/allochaptoken_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp create mode 100644 test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h create mode 100644 test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp create mode 100644 test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h create mode 100644 test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/checknativedcap_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp create mode 100644 test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h create mode 100644 test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp create mode 100644 test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h create mode 100644 test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp create mode 100644 test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h create mode 100644 test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/deletetoken_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.cpp create mode 100644 test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h create mode 100644 test/fuzztest/access_token/deletetoken_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp create mode 100644 test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h create mode 100644 test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp create mode 100644 test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h create mode 100644 test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp create mode 100644 test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h create mode 100644 test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn create mode 100644 test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init create mode 100644 test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml create mode 100644 test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp create mode 100644 test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h diff --git a/bundle.json b/bundle.json index 462bda7bb..c9ae366e5 100644 --- a/bundle.json +++ b/bundle.json @@ -80,11 +80,7 @@ "//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/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" + "//base/security/access_token/test/fuzztest/access_token:fuzztest" ] } } diff --git a/test/fuzztest/access_token/BUILD.gn b/test/fuzztest/access_token/BUILD.gn new file mode 100644 index 000000000..2e063a6b2 --- /dev/null +++ b/test/fuzztest/access_token/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + "allochaptoken_fuzzer:AllocHapTokenFuzzTest", + "alloclocaltokenid_fuzzer:AllocLocalTokenIDFuzzTest", + "checknativedcap_fuzzer:CheckNativeDCapFuzzTest", + "clearusergrantedpermissionstate_fuzzer:ClearUserGrantedPermissionStateFuzzTest", + "deleteremotedevicetokens_fuzzer:DeleteRemoteDeviceTokensFuzzTest", + "deleteremotetoken_fuzzer:DeleteRemoteTokenFuzzTest", + "deletetoken_fuzzer:DeleteTokenFuzzTest", + "getdefpermission_fuzzer:GetDefPermissionFuzzTest", + "getpermissionflags_fuzzer:GetPermissionFlagsFuzzTest", + "grantpermission_fuzzer:GrantPermissionFuzzTest", + "revokeusergrantedpermission_fuzzer:RevokeUserGrantedPermissionFuzzTest", + "setremotehaptokeninfo_fuzzer:SetRemoteHapTokenInfoFuzzTest", + "setremotenativetokeninfo_fuzzer:SetRemoteNativeTokenInfoFuzzTest", + "updatehaptoken_fuzzer:UpdateHapTokenFuzzTest", + "verifyaccesstoken_fuzzer:VerifyAccessTokenFuzzTest", + "verifyaccesstoken001_fuzzer:VerifyAccessToken001FuzzTest", + ] +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn new file mode 100644 index 000000000..904b51553 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("AllocHapTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/allochaptoken_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 = [ "allochaptoken_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", + ] +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp new file mode 100644 index 000000000..6fa684683 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp @@ -0,0 +1,101 @@ +/* + * 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 "allochaptoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool AllocHapTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + std::string testdata; + AccessTokenIDEx tokenIdEx = {0}; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + PermissionDef TestPermDef1 = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1 + }; + + PermissionDef TestPermDef2 = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1, + + }; + + PermissionStateFull TestState1 = { + .permissionName = testdata, + .isGeneral = true, + .resDeviceID = {testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1}, + }; + + PermissionStateFull TestState2 = { + .permissionName = testdata, + .isGeneral = false, + .resDeviceID = {testdata, testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1, 2} + }; + HapInfoParams TestInfoParms = { + .userID = 1, + .bundleName = testdata, + .instIndex = 0, + .appIDDesc = testdata + }; + HapPolicyParams TestPolicyPrams = { + .apl = APL_NORMAL, + .domain = testdata, + .permList = {TestPermDef1, TestPermDef2}, + .permStateList = {TestState1, TestState2} + }; + + tokenIdEx = AccessTokenKit::AllocHapToken(TestInfoParms, TestPolicyPrams); + } + return tokenIdEx.tokenIdExStruct.tokenID != 0; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AllocHapTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.h new file mode 100644 index 000000000..e2ceda0b5 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_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_ALLOCHAPTOKEN_FUZZER_H +#define TEST_FUZZTEST_ALLOCHAPTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "allochaptoken_fuzzer" + +#endif // TEST_FUZZTEST_ALLOCHAPTOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init b/test/fuzztest/access_token/allochaptoken_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_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/allochaptoken_fuzzer/project.xml b/test/fuzztest/access_token/allochaptoken_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn new file mode 100644 index 000000000..c79db1085 --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("AllocLocalTokenIDFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/alloclocaltokenid_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 = [ "alloclocaltokenid_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", + ] +} diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp new file mode 100644 index 000000000..993f3a079 --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "alloclocaltokenid_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool AllocLocalTokenIDFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + AccessTokenID TOKENID = 0; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID REMOTETOKENID = static_cast(size); + TOKENID = AccessTokenKit::AllocLocalTokenID(reinterpret_cast(data), REMOTETOKENID); + } + return TOKENID != 0; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AllocLocalTokenIDFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_fuzzer.h new file mode 100644 index 000000000..24cc37870 --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/alloclocaltokenid_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_ALLOCLOCALTOKENID_FUZZER_H +#define TEST_FUZZTEST_ALLOCLOCALTOKENID_FUZZER_H + +#define FUZZ_PROJECT_NAME "alloclocaltokenid_fuzzer" + +#endif // TEST_FUZZTEST_ALLOCLOCALTOKENID_FUZZER_H diff --git a/test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_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/alloclocaltokenid_fuzzer/project.xml b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/alloclocaltokenid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn b/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn new file mode 100644 index 000000000..0cf9f2307 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("CheckNativeDCapFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/checknativedcap_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 = [ "checknativedcap_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", + ] +} diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.cpp new file mode 100644 index 000000000..7b22eff36 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_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 "checknativedcap_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool CheckNativeDCapFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::CheckNativeDCap(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::CheckNativeDCapFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_fuzzer.h new file mode 100644 index 000000000..4da892de7 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/checknativedcap_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_CHECKNATIVEDCAP_FUZZER_H +#define TEST_FUZZTEST_CHECKNATIVEDCAP_FUZZER_H + +#define FUZZ_PROJECT_NAME "checknativedcap_fuzzer" + +#endif // TEST_FUZZTEST_CHECKNATIVEDCAP_FUZZER_H diff --git a/test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init b/test/fuzztest/access_token/checknativedcap_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_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/checknativedcap_fuzzer/project.xml b/test/fuzztest/access_token/checknativedcap_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/checknativedcap_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn new file mode 100644 index 000000000..fc80c90eb --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("ClearUserGrantedPermissionStateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/clearusergrantedpermissionstate_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 = [ "clearusergrantedpermissionstate_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", + ] +} diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.cpp new file mode 100644 index 000000000..18f55fbd2 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_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 "clearusergrantedpermissionstate_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool ClearUserGrantedPermissionStateFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::ClearUserGrantedPermissionState(TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ClearUserGrantedPermissionStateFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_fuzzer.h new file mode 100644 index 000000000..042746200 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/clearusergrantedpermissionstate_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_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H +#define TEST_FUZZTEST_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H + +#define FUZZ_PROJECT_NAME "clearusergrantedpermissionstate_fuzzer" + +#endif // TEST_FUZZTEST_CLEARUSERGRANTEDPERMISSIONSTATE_FUZZER_H diff --git a/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_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/clearusergrantedpermissionstate_fuzzer/project.xml b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/clearusergrantedpermissionstate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn new file mode 100644 index 000000000..97bd5ba28 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("DeleteRemoteDeviceTokensFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deleteremotedevicetokens_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 = [ "deleteremotedevicetokens_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", + ] +} diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_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/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp new file mode 100644 index 000000000..3350c7640 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "deleteremotedevicetokens_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + + +namespace OHOS { + bool DeleteRemoteDeviceTokensFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + result = AccessTokenKit::DeleteRemoteDeviceTokens(reinterpret_cast(data)); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + + OHOS::DeleteRemoteDeviceTokensFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_fuzzer.h new file mode 100644 index 000000000..efd039c24 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/deleteremotedevicetokens_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_DELETEREMOTEDEVICETOKENS_FUZZER_H +#define TEST_FUZZTEST_DELETEREMOTEDEVICETOKENS_FUZZER_H + +#define FUZZ_PROJECT_NAME "deleteremotedevicetokens_fuzzer" + +#endif // TEST_FUZZTEST_DELETEREMOTEDEVICETOKENS_FUZZER_H diff --git a/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/deleteremotedevicetokens_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn new file mode 100644 index 000000000..9ff378294 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("DeleteRemoteTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deleteremotetoken_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 = [ "deleteremotetoken_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", + ] +} diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init b/test/fuzztest/access_token/deleteremotetoken_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_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/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp new file mode 100644 index 000000000..ad64a0160 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp @@ -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. + */ + +#include "deleteremotetoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + + + +namespace OHOS { + bool DeleteRemoteTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::DeleteRemoteToken(reinterpret_cast(data), TOKENID); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DeleteRemoteTokenFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.h new file mode 100644 index 000000000..594034594 --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_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_DELETEREMOTETOKEN_FUZZER_H +#define TEST_FUZZTEST_DELETEREMOTETOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "deleteremotetoken_fuzzer" + +#endif // TEST_FUZZTEST_DELETEREMOTETOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml b/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn new file mode 100644 index 000000000..1f0cc35a5 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("DeleteTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/deletetoken_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 = [ "deletetoken_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", + ] +} diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/corpus/init b/test/fuzztest/access_token/deletetoken_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_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/deletetoken_fuzzer/deletetoken_fuzzer.cpp b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.cpp new file mode 100644 index 000000000..93cd4c843 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_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 "deletetoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool DeleteTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::DeleteToken(TOKENID); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DeleteTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_fuzzer.h new file mode 100644 index 000000000..1f0a40115 --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/deletetoken_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_DELETETOKEN_FUZZER_H +#define TEST_FUZZTEST_DELETETOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "deletetoken_fuzzer" + +#endif // TEST_FUZZTEST_DELETETOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/deletetoken_fuzzer/project.xml b/test/fuzztest/access_token/deletetoken_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/deletetoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn index 92743d205..6b4f7ae03 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GetDefPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -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 aa3218083..38fbe3a3d 100644 --- a/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp +++ b/test/fuzztest/access_token/getdefpermission_fuzzer/getdefpermission_fuzzer.cpp @@ -30,21 +30,23 @@ namespace OHOS { bool GetDefPermissionFuzzTest(const uint8_t* data, size_t size) { bool result = false; + std::string testdata; if ((data == nullptr) || (size <= 0)) { return result; } if (size > 0) { + testdata = reinterpret_cast(data); PermissionDef PERMISSIONDEF = { - .permissionName = reinterpret_cast(data), - .bundleName = reinterpret_cast(data), + .permissionName = testdata, + .bundleName = testdata, .grantMode = 1, - .label = reinterpret_cast(data), + .label = testdata, .labelId = 1, - .description = reinterpret_cast(data), + .description = testdata, .availableLevel = APL_NORMAL, .descriptionId = 1 }; - result = AccessTokenKit::GetDefPermission(reinterpret_cast(data), PERMISSIONDEF); + result = AccessTokenKit::GetDefPermission(testdata, PERMISSIONDEF); } return result; } diff --git a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn index 9a70902d0..0ee9e2ade 100644 --- a/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/getpermissionflags_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GetPermissionFlagsFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":GetPermissionFlagsFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn index 987aa46ac..54534c61e 100644 --- a/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/grantpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("GrantPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":GrantPermissionFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn index ba5d208a1..b12e58998 100644 --- a/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/revokeusergrantedpermission_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("RevokeUserGrantedPermissionFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":RevokeUserGrantedPermissionFuzzTest", - ] -} diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn new file mode 100644 index 000000000..8160aaf1f --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("SetRemoteHapTokenInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/setremotehaptokeninfo_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 = [ "setremotehaptokeninfo_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", + ] +} diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_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/setremotehaptokeninfo_fuzzer/project.xml b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp new file mode 100644 index 000000000..b4b69c86f --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * 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 "setremotehaptokeninfo_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool SetRemoteHapTokenInfoFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; +#ifdef TOKEN_SYNC_ENABLE + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + AccessTokenID TOKENID = static_cast(size); + HapTokenInfo baseInfo = { + .apl = APL_NORMAL, + .ver = 1, + .userID = 1, + .bundleName = testdata, + .instIndex = 1, + .appID = testdata, + .deviceID = testdata, + .tokenID = TOKENID, + .tokenAttr = 0 + }; + PermissionStateFull infoManagerTestState = { + .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .isGeneral = true, + .permissionName = testdata, + .resDeviceID = {testdata}}; + std::vector permStateList; + permStateList.emplace_back(infoManagerTestState); + HapTokenInfoForSync remoteTokenInfo = { + .baseInfo = baseInfo, + .permStateList = permStateList + }; + + result = AccessTokenKit::SetRemoteHapTokenInfo(reinterpret_cast(data), remoteTokenInfo); + } +#endif + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetRemoteHapTokenInfoFuzzTest(data, size); + return 0; +} + diff --git a/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_fuzzer.h new file mode 100644 index 000000000..2a06877e6 --- /dev/null +++ b/test/fuzztest/access_token/setremotehaptokeninfo_fuzzer/setremotehaptokeninfo_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_SETREMOTEHAPTOKENINFO_FUZZER_H +#define TEST_FUZZTEST_SETREMOTEHAPTOKENINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "setremotehaptokeninfo_fuzzer" + +#endif // TEST_FUZZTEST_SETREMOTEHAPTOKENINFO_FUZZER_H diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn new file mode 100644 index 000000000..c9db092dc --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("SetRemoteNativeTokenInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/setremotenativetokeninfo_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 = [ "setremotenativetokeninfo_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", + ] +} diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_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/setremotenativetokeninfo_fuzzer/project.xml b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp new file mode 100644 index 000000000..60f33a711 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * 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 "setremotenativetokeninfo_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool SetRemoteNativeTokenInfoFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + +#ifdef TOKEN_SYNC_ENABLE + + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + testdata = reinterpret_cast(data); + AccessTokenID TOKENID = static_cast(size); + NativeTokenInfoForSync native1 = { + .baseInfo.apl = APL_NORMAL, + .baseInfo.ver = 1, + .baseInfo.processName = testdata, + .baseInfo.dcap = {testdata, testdata}, + .baseInfo.tokenID = TOKENID, + .baseInfo.tokenAttr = 0, + .baseInfo.nativeAcls = {testdata}, + }; + + std::vector nativeTokenInfoList; + nativeTokenInfoList.emplace_back(native1); + + result = AccessTokenKit::SetRemoteNativeTokenInfo(reinterpret_cast(data), nativeTokenInfoList); + } + +#endif + + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::SetRemoteNativeTokenInfoFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_fuzzer.h new file mode 100644 index 000000000..4c681fd78 --- /dev/null +++ b/test/fuzztest/access_token/setremotenativetokeninfo_fuzzer/setremotenativetokeninfo_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_SETREMOTENATIVETOKENINFO_FUZZER_H +#define TEST_FUZZTEST_SETREMOTENATIVETOKENINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "setremotenativetokeninfo_fuzzer" + +#endif // TEST_FUZZTEST_SETREMOTENATIVETOKENINFO_FUZZER_H diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn new file mode 100644 index 000000000..9a7c0c830 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("UpdateHapTokenFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/updatehaptoken_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 = [ "updatehaptoken_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", + ] +} diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init b/test/fuzztest/access_token/updatehaptoken_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_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/updatehaptoken_fuzzer/project.xml b/test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp new file mode 100644 index 000000000..16da0fff0 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp @@ -0,0 +1,96 @@ +/* + * 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 "updatehaptoken_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool UpdateHapTokenFuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + std::string testdata; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + testdata = reinterpret_cast(data); + PermissionDef TestPermDef1 = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1 + }; + + PermissionDef TestPermDef2 = { + .permissionName = testdata, + .bundleName = testdata, + .grantMode = 1, + .availableLevel = APL_NORMAL, + .label = testdata, + .labelId = 1, + .description = testdata, + .descriptionId = 1, + + }; + + PermissionStateFull TestState1 = { + .permissionName = testdata, + .isGeneral = true, + .resDeviceID = {testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1}, + }; + + PermissionStateFull TestState2 = { + .permissionName = testdata, + .isGeneral = false, + .resDeviceID = {testdata, testdata}, + .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1, 2} + }; + + HapPolicyParams TestPolicyPrams = { + .apl = APL_NORMAL, + .domain = testdata, + .permList = {TestPermDef1, TestPermDef2}, + .permStateList = {TestState1, TestState2} + }; + + result = AccessTokenKit::UpdateHapToken(TOKENID, testdata, TestPolicyPrams); + } + return result; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::UpdateHapTokenFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.h new file mode 100644 index 000000000..5eb0c5ea1 --- /dev/null +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_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_UPDATEHAPTOKEN_FUZZER_H +#define TEST_FUZZTEST_UPDATEHAPTOKEN_FUZZER_H + +#define FUZZ_PROJECT_NAME "updatehaptoken_fuzzer" + +#endif // TEST_FUZZTEST_UPDATEHAPTOKEN_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn new file mode 100644 index 000000000..77851ad1b --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# 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("VerifyAccessToken001FuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//base/security/access_token/test/fuzztest/access_token/verifyaccesstoken001_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 = [ "verifyaccesstoken001_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", + ] +} diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/corpus/init new file mode 100644 index 000000000..bc977bd97 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_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/verifyaccesstoken001_fuzzer/project.xml b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.cpp new file mode 100644 index 000000000..ec6ff9368 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_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 "verifyaccesstoken001_fuzzer.h" + +#include +#include +#include +#undef private +#include "accesstoken_kit.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { + bool VerifyAccessToken001FuzzTest(const uint8_t* data, size_t size) + { + bool result = false; + if ((data == nullptr) || (size <= 0)) { + return result; + } + if (size > 0) { + AccessTokenID TOKENID = static_cast(size); + result = AccessTokenKit::VerifyAccessToken(TOKENID, 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::VerifyAccessToken001FuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_fuzzer.h new file mode 100644 index 000000000..78473a298 --- /dev/null +++ b/test/fuzztest/access_token/verifyaccesstoken001_fuzzer/verifyaccesstoken001_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_VERIFYACCESSTOKEN001_FUZZER_H +#define TEST_FUZZTEST_VERIFYACCESSTOKEN001_FUZZER_H + +#define FUZZ_PROJECT_NAME "verifyaccesstoken001_fuzzer" + +#endif // TEST_FUZZTEST_VERIFYACCESSTOKEN001_FUZZER_H diff --git a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn index 3357958b6..cc08fd4fc 100644 --- a/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn +++ b/test/fuzztest/access_token/verifyaccesstoken_fuzzer/BUILD.gn @@ -44,13 +44,3 @@ ohos_fuzztest("VerifyAccessTokenFuzzTest") { "LOG_DOMAIN = 0xD001B00", ] } - -group("fuzztest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":VerifyAccessTokenFuzzTest", - ] -} -- Gitee From 6be4086f2ffa8e4e99b91068e7847bf0447c171b Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Tue, 17 May 2022 11:10:43 +0800 Subject: [PATCH 2/2] cwm_0517_fuzz Signed-off-by: cc_ggboy --- test/fuzztest/access_token/BUILD.gn | 2 +- .../allochaptoken_fuzzer.cpp | 29 +++--------------- .../deleteremotetoken_fuzzer.cpp | 2 -- .../updatehaptoken_fuzzer.cpp | 30 +++---------------- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/test/fuzztest/access_token/BUILD.gn b/test/fuzztest/access_token/BUILD.gn index 2e063a6b2..e37d93e7f 100644 --- a/test/fuzztest/access_token/BUILD.gn +++ b/test/fuzztest/access_token/BUILD.gn @@ -31,7 +31,7 @@ group("fuzztest") { "setremotehaptokeninfo_fuzzer:SetRemoteHapTokenInfoFuzzTest", "setremotenativetokeninfo_fuzzer:SetRemoteNativeTokenInfoFuzzTest", "updatehaptoken_fuzzer:UpdateHapTokenFuzzTest", - "verifyaccesstoken_fuzzer:VerifyAccessTokenFuzzTest", "verifyaccesstoken001_fuzzer:VerifyAccessToken001FuzzTest", + "verifyaccesstoken_fuzzer:VerifyAccessTokenFuzzTest", ] } diff --git a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp index 6fa684683..094fa5d6e 100644 --- a/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp +++ b/test/fuzztest/access_token/allochaptoken_fuzzer/allochaptoken_fuzzer.cpp @@ -35,7 +35,7 @@ namespace OHOS { } if (size > 0) { testdata = reinterpret_cast(data); - PermissionDef TestPermDef1 = { + PermissionDef TestPermDef = { .permissionName = testdata, .bundleName = testdata, .grantMode = 1, @@ -45,34 +45,13 @@ namespace OHOS { .description = testdata, .descriptionId = 1 }; - - PermissionDef TestPermDef2 = { - .permissionName = testdata, - .bundleName = testdata, - .grantMode = 1, - .availableLevel = APL_NORMAL, - .label = testdata, - .labelId = 1, - .description = testdata, - .descriptionId = 1, - - }; - - PermissionStateFull TestState1 = { + PermissionStateFull TestState = { .permissionName = testdata, .isGeneral = true, .resDeviceID = {testdata}, .grantStatus = {PermissionState::PERMISSION_GRANTED}, .grantFlags = {1}, }; - - PermissionStateFull TestState2 = { - .permissionName = testdata, - .isGeneral = false, - .resDeviceID = {testdata, testdata}, - .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED}, - .grantFlags = {1, 2} - }; HapInfoParams TestInfoParms = { .userID = 1, .bundleName = testdata, @@ -82,8 +61,8 @@ namespace OHOS { HapPolicyParams TestPolicyPrams = { .apl = APL_NORMAL, .domain = testdata, - .permList = {TestPermDef1, TestPermDef2}, - .permStateList = {TestState1, TestState2} + .permList = {TestPermDef}, + .permStateList = {TestState} }; tokenIdEx = AccessTokenKit::AllocHapToken(TestInfoParms, TestPolicyPrams); diff --git a/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp index ad64a0160..bcd031a6b 100644 --- a/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp +++ b/test/fuzztest/access_token/deleteremotetoken_fuzzer/deleteremotetoken_fuzzer.cpp @@ -24,8 +24,6 @@ using namespace std; using namespace OHOS::Security::AccessToken; - - namespace OHOS { bool DeleteRemoteTokenFuzzTest(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp index 16da0fff0..4fcdd1c35 100644 --- a/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp +++ b/test/fuzztest/access_token/updatehaptoken_fuzzer/updatehaptoken_fuzzer.cpp @@ -35,7 +35,7 @@ namespace OHOS { if (size > 0) { AccessTokenID TOKENID = static_cast(size); testdata = reinterpret_cast(data); - PermissionDef TestPermDef1 = { + PermissionDef TestPermDef = { .permissionName = testdata, .bundleName = testdata, .grantMode = 1, @@ -45,40 +45,18 @@ namespace OHOS { .description = testdata, .descriptionId = 1 }; - - PermissionDef TestPermDef2 = { - .permissionName = testdata, - .bundleName = testdata, - .grantMode = 1, - .availableLevel = APL_NORMAL, - .label = testdata, - .labelId = 1, - .description = testdata, - .descriptionId = 1, - - }; - - PermissionStateFull TestState1 = { + PermissionStateFull TestState = { .permissionName = testdata, .isGeneral = true, .resDeviceID = {testdata}, .grantStatus = {PermissionState::PERMISSION_GRANTED}, .grantFlags = {1}, }; - - PermissionStateFull TestState2 = { - .permissionName = testdata, - .isGeneral = false, - .resDeviceID = {testdata, testdata}, - .grantStatus = {PermissionState::PERMISSION_GRANTED, PermissionState::PERMISSION_GRANTED}, - .grantFlags = {1, 2} - }; - HapPolicyParams TestPolicyPrams = { .apl = APL_NORMAL, .domain = testdata, - .permList = {TestPermDef1, TestPermDef2}, - .permStateList = {TestState1, TestState2} + .permList = {TestPermDef}, + .permStateList = {TestState} }; result = AccessTokenKit::UpdateHapToken(TOKENID, testdata, TestPolicyPrams); -- Gitee