From a61b4d01e24c6286231982ba4db93147e6cb739f Mon Sep 17 00:00:00 2001 From: wuliushuan Date: Tue, 17 Jun 2025 20:40:19 +0800 Subject: [PATCH] =?UTF-8?q?FUZZ=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliushuan Change-Id: Iee126ea157edc506251d35b3efbe39315febe648 --- test/fuzztest/innerkits/accesstoken/BUILD.gn | 3 + .../accesstokenkitcoverage_fuzzer/BUILD.gn | 44 +++++++++++ .../accesstokenkitcoverage_fuzzer.cpp | 62 +++++++++++++++ .../accesstokenkitcoverage_fuzzer.h | 21 +++++ .../accesstokenkitcoverage_fuzzer/corpus/init | 14 ++++ .../accesstokenkitcoverage_fuzzer/project.xml | 25 ++++++ .../inituserpolicy_fuzzer/BUILD.gn | 44 +++++++++++ .../inituserpolicy_fuzzer/corpus/init | 14 ++++ .../inituserpolicy_fuzzer.cpp | 59 ++++++++++++++ .../inituserpolicy_fuzzer.h | 21 +++++ .../inituserpolicy_fuzzer/project.xml | 25 ++++++ .../BUILD.gn | 2 + ...registerpermstatechangecallback_fuzzer.cpp | 19 ++++- .../registertokensynccallback_fuzzer/BUILD.gn | 45 +++++++++++ .../corpus/init | 13 +++ .../project.xml | 25 ++++++ .../registertokensynccallback_fuzzer.cpp | 79 +++++++++++++++++++ .../registertokensynccallback_fuzzer.h | 21 +++++ 18 files changed, 533 insertions(+), 3 deletions(-) create mode 100644 test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/BUILD.gn create mode 100644 test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.cpp create mode 100644 test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.h create mode 100644 test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/corpus/init create mode 100644 test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/project.xml create mode 100644 test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/BUILD.gn create mode 100644 test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/corpus/init create mode 100644 test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.cpp create mode 100644 test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.h create mode 100644 test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/project.xml create mode 100644 test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/BUILD.gn create mode 100644 test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/corpus/init create mode 100644 test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/project.xml create mode 100644 test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.cpp create mode 100644 test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.h diff --git a/test/fuzztest/innerkits/accesstoken/BUILD.gn b/test/fuzztest/innerkits/accesstoken/BUILD.gn index e7e49c309..6c6db4eee 100644 --- a/test/fuzztest/innerkits/accesstoken/BUILD.gn +++ b/test/fuzztest/innerkits/accesstoken/BUILD.gn @@ -29,6 +29,7 @@ group("fuzztest") { "gethapdlpflag_fuzzer:GetHapDlpFlagFuzzTest", "gethaptokenid_fuzzer:GetHapTokenIDFuzzTest", "gethaptokeninfo_fuzzer:GetHapTokenInfoFuzzTest", + "accesstokenkitcoverage_fuzzer:AccessTokenKitCoverageFuzzTest", "gethaptokeninfofromremote_fuzzer:GetHapTokenInfoFromRemoteFuzzTest", "getnativetokenid_fuzzer:GetNativeTokenIdFuzzTest", "getnativetokeninfo_fuzzer:GetNativeTokenInfoFuzzTest", @@ -47,8 +48,10 @@ group("fuzztest") { "grantpermission_fuzzer:GrantPermissionFuzzTest", "grantpermissionforspecifiedtime_fuzzer:GrantPermissionForSpecifiedTimeFuzzTest", "inithaptoken_fuzzer:InitHapTokenFuzzTest", + "inituserpolicy_fuzzer:InitUserPolicyFuzzTest", "istoastshownneeded_fuzzer:IsToastShownNeededFuzzTest", "registerpermstatechangecallback_fuzzer:RegisterPermStateChangeCallbackFuzzTest", + "registertokensynccallback_fuzzer:RegisterTokenSyncCallbackFuzzTest", "requestapppermonsetting_fuzzer:RequestAppPermOnSettingFuzzTest", "revokeusergrantedpermission_fuzzer:RevokeUserGrantedPermissionFuzzTest", "setpermdialogcap_fuzzer:SetPermDialogCapFuzzTest", diff --git a/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/BUILD.gn b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/BUILD.gn new file mode 100644 index 000000000..ad40c6192 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2025 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") +import("../../../../../access_token.gni") + +ohos_fuzztest("AccessTokenKitCoverageFuzzTest") { + module_out_path = module_output_path_interface_access_token + fuzz_config_file = "." + + include_dirs = [ + "${access_token_path}/interfaces/innerkits/accesstoken/include", + "${access_token_path}/test/fuzztest/common", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "accesstokenkitcoverage_fuzzer.cpp" ] + + deps = [ + "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + ] + + configs = [ "${access_token_path}/config:coverage_flags" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] +} diff --git a/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.cpp b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.cpp new file mode 100644 index 000000000..17057ee43 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 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 "accesstokenkitcoverage_fuzzer.h" + +#include +#include +#include +#include +#undef private +#include "accesstoken_fuzzdata.h" +#include "accesstoken_kit.h" +#include "access_token.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +bool AccessTokenKitCoverageFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + + AccessTokenFuzzData fuzzData(data, size); + + std::string permissionName(fuzzData.GenerateStochasticString()); + AccessTokenID tokenID = fuzzData.GetData(); + HapTokenInfoExt info; + AccessTokenKit::GetHapTokenInfoExtension(tokenID, info); + std::vector kernelPermList; + AccessTokenKit::GetKernelPermissions(tokenID, kernelPermList); + std::string value; + AccessTokenKit::GetReqPermissionByName(tokenID, permissionName, value); + uint32_t version; + AccessTokenKit::GetVersion(version); + PermissionGrantInfo grantInfo; + AccessTokenKit::GetPermissionManagerInfo(grantInfo); + + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AccessTokenKitCoverageFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.h b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.h new file mode 100644 index 000000000..3ff6602f1 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/accesstokenkitcoverage_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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_GETHAPTOKENINFOEXTENSION_FUZZER_H +#define TEST_FUZZTEST_GETHAPTOKENINFOEXTENSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "accesstokenkitcoverage_fuzzer" + +#endif // TEST_FUZZTEST_GETHAPTOKENINFOEXTENSION_FUZZER_H diff --git a/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/corpus/init b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/corpus/init new file mode 100644 index 000000000..da556996e --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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. + +6F686F732E7065726D697373696F6E2E43414D4552415c0015460020 \ No newline at end of file diff --git a/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/project.xml b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/accesstokenkitcoverage_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/BUILD.gn b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/BUILD.gn new file mode 100644 index 000000000..bf7047c99 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2025 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") +import("../../../../../access_token.gni") + +ohos_fuzztest("InitUserPolicyFuzzTest") { + module_out_path = module_output_path_interface_access_token + fuzz_config_file = "." + + include_dirs = [ + "${access_token_path}/interfaces/innerkits/accesstoken/include", + "${access_token_path}/test/fuzztest/common", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "inituserpolicy_fuzzer.cpp" ] + + deps = [ + "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + ] + + configs = [ "${access_token_path}/config:coverage_flags" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] +} diff --git a/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/corpus/init b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/corpus/init new file mode 100644 index 000000000..dc822145b --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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. + +6F686F732E7065726D697373696F6E2E43414D4552415c0000000000 \ No newline at end of file diff --git a/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.cpp b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.cpp new file mode 100644 index 000000000..1ab0898ae --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 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 "inituserpolicy_fuzzer.h" + +#include +#include +#include +#include +#undef private +#include "accesstoken_fuzzdata.h" +#include "accesstoken_kit.h" +#include "access_token.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +bool InitUserPolicyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } + + AccessTokenFuzzData fuzzData(data, size); + + std::string permissionName(fuzzData.GenerateStochasticString()); + const std::vector permList = {permissionName}; + UserState state; + state.userId = fuzzData.GetData(); + state.isActive = fuzzData.GenerateStochasticBool(); + std::vector userList = {state}; + AccessTokenKit::InitUserPolicy(userList, permList); + AccessTokenKit::UpdateUserPolicy(userList); + AccessTokenKit::ClearUserPolicy(); + + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::InitUserPolicyFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.h b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.h new file mode 100644 index 000000000..25c0f036a --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/inituserpolicy_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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_INITUSERPOLICY_FUZZER_H +#define TEST_FUZZTEST_INITUSERPOLICY_FUZZER_H + +#define FUZZ_PROJECT_NAME "inituserpolicy_fuzzer" + +#endif // TEST_FUZZTEST_INITUSERPOLICY_FUZZER_H diff --git a/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/project.xml b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/inituserpolicy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/BUILD.gn b/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/BUILD.gn index 016a16639..5bf45d2e2 100644 --- a/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/BUILD.gn +++ b/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/BUILD.gn @@ -20,6 +20,8 @@ ohos_fuzztest("RegisterPermStateChangeCallbackFuzzTest") { fuzz_config_file = "." include_dirs = [ "${access_token_path}/interfaces/innerkits/accesstoken/include", + "${access_token_path}/interfaces/innerkits/accesstoken/src", + "${access_token_path}/frameworks/accesstoken/include", "${access_token_path}/test/fuzztest/common", ] cflags = [ diff --git a/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/registerpermstatechangecallback_fuzzer.cpp b/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/registerpermstatechangecallback_fuzzer.cpp index 85ce02414..6e6a6e565 100644 --- a/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/registerpermstatechangecallback_fuzzer.cpp +++ b/test/fuzztest/innerkits/accesstoken/registerpermstatechangecallback_fuzzer/registerpermstatechangecallback_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,8 +18,12 @@ #include #include #include +#include "accesstoken_callbacks.h" #include "accesstoken_fuzzdata.h" #include "accesstoken_kit.h" +#define private public +#include "accesstoken_manager_client.h" +#undef private using namespace std; using namespace OHOS::Security::AccessToken; @@ -54,9 +58,18 @@ namespace OHOS { scopeInfo.permList = { fuzzData.GenerateStochasticString() }; scopeInfo.tokenIDs = { fuzzData.GetData() }; auto callbackPtr = std::make_shared(scopeInfo); - int32_t result = AccessTokenKit::RegisterPermStateChangeCallback(callbackPtr); + AccessTokenKit::RegisterPermStateChangeCallback(callbackPtr); + auto callback = new (std::nothrow) PermissionStateChangeCallback(callbackPtr); + if (callback == nullptr) { + return true; + } + AccessTokenManagerClient::GetInstance().callbackMap_[callbackPtr] = callback; + AccessTokenKit::UnRegisterPermStateChangeCallback(callbackPtr); + auto callbackPtr2 = std::make_shared(scopeInfo); + AccessTokenKit::RegisterSelfPermStateChangeCallback(callbackPtr2); + AccessTokenKit::UnRegisterSelfPermStateChangeCallback(callbackPtr); - return result == RET_SUCCESS; + return true; } } diff --git a/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/BUILD.gn b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/BUILD.gn new file mode 100644 index 000000000..19ba09ddc --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2025 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") +import("../../../../../access_token.gni") + +ohos_fuzztest("RegisterTokenSyncCallbackFuzzTest") { + module_out_path = module_output_path_interface_access_token + fuzz_config_file = "." + include_dirs = + [ "${access_token_path}/interfaces/innerkits/accesstoken/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "registertokensynccallback_fuzzer.cpp" ] + deps = [ + "${access_token_path}/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "${access_token_path}/interfaces/innerkits/token_setproc:libtoken_setproc", + ] + + configs = [ "${access_token_path}/config:coverage_flags" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + if (token_sync_enable == true) { + cflags_cc = [ "-DTOKEN_SYNC_ENABLE" ] + } +} diff --git a/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/corpus/init b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 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/innerkits/accesstoken/registertokensynccallback_fuzzer/project.xml b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/project.xml new file mode 100644 index 000000000..66e1dcac4 --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.cpp b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.cpp new file mode 100644 index 000000000..ef00997aa --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 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 "registertokensynccallback_fuzzer.h" + +#include "accesstoken_kit.h" +#include "token_setproc.h" +#include "token_sync_kit_interface.h" + +using namespace std; +using namespace OHOS::Security::AccessToken; +namespace { +class TokenSyncCallback : public TokenSyncKitInterface { +public: + ~TokenSyncCallback() = default; + int32_t GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) const override + { + return TokenSyncError::TOKEN_SYNC_OPENSOURCE_DEVICE; // TOKEN_SYNC_OPENSOURCE_DEVICE is a test + }; + + int32_t DeleteRemoteHapTokenInfo(AccessTokenID tokenID) const override + { + return TokenSyncError::TOKEN_SYNC_SUCCESS; // TOKEN_SYNC_SUCCESS is a test + }; + + int32_t UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo) const override + { + return TokenSyncError::TOKEN_SYNC_SUCCESS; // TOKEN_SYNC_SUCCESS is a test + }; +}; + +bool NativeTokenGet() +{ + AccessTokenID token = AccessTokenKit::GetNativeTokenId("token_sync_service"); + if (token == 0) { + return false; + } + SetSelfTokenID(token); + return true; +} +}; + +namespace OHOS { +bool RegisterTokenSyncCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return false; + } +#ifdef TOKEN_SYNC_ENABLE + if (!NativeTokenGet()) { + return false; + } + std::shared_ptr callback = std::make_shared(); + AccessTokenKit::RegisterTokenSyncCallback(callback); + AccessTokenKit::UnRegisterTokenSyncCallback(); + #endif // TOKEN_SYNC_ENABLE + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::RegisterTokenSyncCallbackFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.h b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.h new file mode 100644 index 000000000..50749832d --- /dev/null +++ b/test/fuzztest/innerkits/accesstoken/registertokensynccallback_fuzzer/registertokensynccallback_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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_REGISTERTOKENSYNCCALLBACK_FUZZER_H +#define TEST_FUZZTEST_REGISTERTOKENSYNCCALLBACK_FUZZER_H + +#define FUZZ_PROJECT_NAME "registertokensynccallback_fuzzer" + +#endif // TEST_FUZZTEST_REGISTERTOKENSYNCCALLBACK_FUZZER_H \ No newline at end of file -- Gitee