diff --git a/frameworks/common/BUILD.gn b/frameworks/common/BUILD.gn index 41fcfa310005afae6e166659d03bf6f2667d1f9b..b87867b38c273d6637999cd05723f27b376955ab 100644 --- a/frameworks/common/BUILD.gn +++ b/frameworks/common/BUILD.gn @@ -79,6 +79,9 @@ ohos_static_library("accesstoken_static_log") { ] cflags_cc = [ "-DHILOG_ENABLE" ] + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } ohos_shared_library("accesstoken_common_cxx") { @@ -128,4 +131,7 @@ ohos_shared_library("accesstoken_common_cxx") { ] cflags_cc = [ "-DHILOG_ENABLE" ] + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } diff --git a/frameworks/common/src/accesstoken_common_log.cpp b/frameworks/common/src/accesstoken_common_log.cpp index 47f6fa8e8bc1331f97881b66acc1578510305d34..5ac9e486d237c33adc7fa175b9f53922a134d551 100644 --- a/frameworks/common/src/accesstoken_common_log.cpp +++ b/frameworks/common/src/accesstoken_common_log.cpp @@ -47,6 +47,9 @@ void ClearThreadErrorMsg(void) g_msgLen = 0; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void AppendThreadErrMsg(unsigned int domain, const char *tag, const uint8_t *buff, uint32_t buffLen) { @@ -62,6 +65,9 @@ void AppendThreadErrMsg(unsigned int domain, const char *tag, } g_msgLen += buffLen; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif static bool ReplaceSubstring(unsigned int domain, const char *tag, const char *format, char result[MAX_ERROR_MESSAGE_LEN]) diff --git a/frameworks/common/src/data_validator.cpp b/frameworks/common/src/data_validator.cpp index 329636c472a986101af356759f6725f14b71f15c..023edd9997c28c44bcccb4f2c68a2c184bbf3036 100644 --- a/frameworks/common/src/data_validator.cpp +++ b/frameworks/common/src/data_validator.cpp @@ -34,6 +34,9 @@ bool DataValidator::IsBundleNameValid(const std::string& bundleName) return ret; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif bool DataValidator::IsLabelValid(const std::string& label) { bool ret = (label.length() <= MAX_LENGTH); @@ -51,6 +54,9 @@ bool DataValidator::IsDescValid(const std::string& desc) } return ret; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif bool DataValidator::IsPermissionNameValid(const std::string& permissionName) { diff --git a/frameworks/common/src/time_util.cpp b/frameworks/common/src/time_util.cpp index 6f8f7a0edd24ffef0cb74f69179add12272cd97b..6699c4fac178ae2cbcfde7519df8f34156ced27e 100644 --- a/frameworks/common/src/time_util.cpp +++ b/frameworks/common/src/time_util.cpp @@ -31,6 +31,9 @@ int64_t TimeUtil::GetCurrentTimestamp() return timestamp; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif bool TimeUtil::IsTimeStampsSameMinute(int64_t timeStamp1, int64_t timeStamp2) { struct tm t1 = {0}; @@ -43,6 +46,9 @@ bool TimeUtil::IsTimeStampsSameMinute(int64_t timeStamp1, int64_t timeStamp2) return t1.tm_min == t2.tm_min; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif } // namespace AccessToken } // namespace Security } // namespace OHOS diff --git a/interfaces/innerkits/accesstoken/BUILD.gn b/interfaces/innerkits/accesstoken/BUILD.gn index e330621df71657aab95751965ea54038b350096a..ac3b1cd5149dabded8d67bf349a491196f7926ae 100644 --- a/interfaces/innerkits/accesstoken/BUILD.gn +++ b/interfaces/innerkits/accesstoken/BUILD.gn @@ -96,6 +96,9 @@ if (is_standard_system) { if (security_component_enhance_enable == true) { cflags_cc += [ "-DSECURITY_COMPONENT_ENHANCE_ENABLE" ] } + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } } diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp b/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp index b9c4372ec59c8e2e4bee881034086bb8b87d0bf8..48dddd2b752cba1d1942dae33b39088c26b36bd4 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp +++ b/interfaces/innerkits/accesstoken/src/accesstoken_callbacks.cpp @@ -30,6 +30,9 @@ PermissionStateChangeCallback::PermissionStateChangeCallback( PermissionStateChangeCallback::~PermissionStateChangeCallback() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PermissionStateChangeCallback::PermStateChangeCallback(PermStateChangeInfo& result) { if (customizedCallback_ == nullptr) { @@ -42,6 +45,9 @@ void PermissionStateChangeCallback::PermStateChangeCallback(PermStateChangeInfo& void PermissionStateChangeCallback::Stop() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif #ifdef TOKEN_SYNC_ENABLE TokenSyncCallback::TokenSyncCallback(const std::shared_ptr& tokenSyncCallback) @@ -51,6 +57,9 @@ TokenSyncCallback::TokenSyncCallback(const std::shared_ptrUpdateRemoteHapTokenInfo(tokenInfo); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif #endif // TOKEN_SYNC_ENABLE } // namespace AccessToken } // namespace Security diff --git a/interfaces/innerkits/nativetoken/BUILD.gn b/interfaces/innerkits/nativetoken/BUILD.gn index 1caeae894427823727ad971a3135f003a84cab9b..0e85fd3b73c0836ddd0c5ca867d4bd4c4d6b9eb9 100644 --- a/interfaces/innerkits/nativetoken/BUILD.gn +++ b/interfaces/innerkits/nativetoken/BUILD.gn @@ -52,6 +52,9 @@ if (is_standard_system) { external_deps += [ "selinux_adapter:librestorecon" ] cflags += [ "-DWITH_SELINUX" ] } + if (use_libfuzzer) { + cflags += [ "-DFUZZ_TEST" ] + } } ohos_shared_library("libnativetoken_shared") { @@ -87,5 +90,8 @@ if (is_standard_system) { external_deps += [ "selinux_adapter:librestorecon" ] cflags += [ "-DWITH_SELINUX" ] } + if (use_libfuzzer) { + cflags += [ "-DFUZZ_TEST" ] + } } } diff --git a/interfaces/innerkits/nativetoken/src/nativetoken.c b/interfaces/innerkits/nativetoken/src/nativetoken.c index 093694088f726d6b49b525091e1725869676b7d6..76d387cabfd6c826f1f7ca78376e6788dbbe2ed3 100644 --- a/interfaces/innerkits/nativetoken/src/nativetoken.c +++ b/interfaces/innerkits/nativetoken/src/nativetoken.c @@ -136,6 +136,9 @@ static int32_t GetNativeTokenFromJson(cJSON *cjsonItem, NativeTokenList *tokenNo return ATRET_SUCCESS; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif static void FreeTokenNode(NativeTokenList **node) { if (node == NULL || *node == NULL) { @@ -177,6 +180,9 @@ static void FreeTokenList(void) } g_tokenListHead->next = NULL; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif static int32_t GetTokenList(const cJSON *object) { @@ -241,6 +247,9 @@ static int32_t ParseTokenInfo(void) return ret; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif static int32_t ClearOrCreateCfgFile(void) { int32_t fd = open(TOKEN_ID_CFG_FILE_PATH, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP); @@ -269,6 +278,9 @@ static int32_t ClearOrCreateCfgFile(void) return ATRET_SUCCESS; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int32_t AtlibInit(void) { diff --git a/interfaces/innerkits/privacy/BUILD.gn b/interfaces/innerkits/privacy/BUILD.gn index d1ae53460d51c2ffdc60135d423e552d6a9ace84..4c4273335037075400c4339eae6f7914ce0be30e 100644 --- a/interfaces/innerkits/privacy/BUILD.gn +++ b/interfaces/innerkits/privacy/BUILD.gn @@ -85,5 +85,8 @@ if (is_standard_system) { "-DHILOG_ENABLE", "-DDEBUG_API_PERFORMANCE", ] + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } } diff --git a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp index 252571abf1bcc9afb824a2eed5f095f3c531a69e..ef3d1a02b83e0000fc5908c505586e3ecf7c67b4 100644 --- a/interfaces/innerkits/privacy/src/privacy_manager_client.cpp +++ b/interfaces/innerkits/privacy/src/privacy_manager_client.cpp @@ -47,12 +47,18 @@ PrivacyManagerClient& PrivacyManagerClient::GetInstance() PrivacyManagerClient::PrivacyManagerClient() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif PrivacyManagerClient::~PrivacyManagerClient() { LOGE(PRI_DOMAIN, PRI_TAG, "~PrivacyManagerClient"); std::lock_guard lock(proxyMutex_); ReleaseProxy(); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif static int32_t ConvertResult(int32_t ret) { @@ -423,12 +429,18 @@ void PrivacyManagerClient::InitProxy() } } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PrivacyManagerClient::OnRemoteDiedHandle() { std::lock_guard lock(proxyMutex_); ReleaseProxy(); InitProxy(); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif sptr PrivacyManagerClient::GetProxy() { @@ -439,6 +451,9 @@ sptr PrivacyManagerClient::GetProxy() return proxy_; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PrivacyManagerClient::ReleaseProxy() { if (proxy_ != nullptr && serviceDeathObserver_ != nullptr) { @@ -447,6 +462,9 @@ void PrivacyManagerClient::ReleaseProxy() proxy_ = nullptr; serviceDeathObserver_ = nullptr; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif sptr PrivacyManagerClient::GetAnonyStub() { diff --git a/interfaces/innerkits/token_setproc/BUILD.gn b/interfaces/innerkits/token_setproc/BUILD.gn index 0b0d7d83aaea52a51be31f3150996639f4dceeca..180e923d678099b6fc630ddc9450f51ca033e306 100644 --- a/interfaces/innerkits/token_setproc/BUILD.gn +++ b/interfaces/innerkits/token_setproc/BUILD.gn @@ -32,6 +32,9 @@ if (is_standard_system) { include_dirs = [ "src" ] sources = [ "src/token_setproc.c" ] + if (use_libfuzzer) { + cflags = [ "-DFUZZ_TEST" ] + } } ohos_shared_library("libtokensetproc_shared") { @@ -52,6 +55,9 @@ if (is_standard_system) { include_dirs = [ "src" ] sources = [ "src/token_setproc.c" ] + if (use_libfuzzer) { + cflags = [ "-DFUZZ_TEST" ] + } } ohos_static_library("libperm_setproc") { diff --git a/interfaces/innerkits/token_setproc/src/perm_setproc.cpp b/interfaces/innerkits/token_setproc/src/perm_setproc.cpp index 0aeea7f00cfb2b2ba7ac98a75c3df6c363fc0fa2..01d5b16336f05bcbbeba5bf086347dd253791534 100644 --- a/interfaces/innerkits/token_setproc/src/perm_setproc.cpp +++ b/interfaces/innerkits/token_setproc/src/perm_setproc.cpp @@ -101,6 +101,9 @@ int32_t RemovePermissionFromKernel(uint32_t tokenID) return ACCESS_TOKEN_OK; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif int32_t SetPermissionToKernel(uint32_t tokenID, int32_t opCode, bool status) { struct IoctlSetGetPermData data = { @@ -122,6 +125,9 @@ int32_t SetPermissionToKernel(uint32_t tokenID, int32_t opCode, bool status) return ACCESS_TOKEN_OK; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int32_t GetPermissionFromKernel(uint32_t tokenID, int32_t opCode, bool& isGranted) { diff --git a/interfaces/innerkits/token_setproc/src/token_setproc.c b/interfaces/innerkits/token_setproc/src/token_setproc.c index a5620d1de6929b8f6611b2e3175b138b3b4a482f..e14cf113475ad10b55883e71bfb81a5a8bb7a164 100644 --- a/interfaces/innerkits/token_setproc/src/token_setproc.c +++ b/interfaces/innerkits/token_setproc/src/token_setproc.c @@ -71,6 +71,9 @@ int SetSelfTokenID(uint64_t tokenID) return ACCESS_TOKEN_OK; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif uint64_t GetFirstCallerTokenID(void) { uint64_t token = INVAL_TOKEN_ID; @@ -88,6 +91,9 @@ uint64_t GetFirstCallerTokenID(void) fdsan_close_with_tag(fd, SET_PROC_FD_TAG); return token; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int SetFirstCallerTokenID(uint64_t tokenID) { diff --git a/services/accesstokenmanager/BUILD.gn b/services/accesstokenmanager/BUILD.gn index 7c610f06405b625af31daef0f342f3d4eab30ff5..ca6ae10b3754830409e7c7b0630cf77a5cfc0578 100644 --- a/services/accesstokenmanager/BUILD.gn +++ b/services/accesstokenmanager/BUILD.gn @@ -199,5 +199,9 @@ if (is_standard_system) { if ("${target_platform}" == "watch" || "${target_platform}" == "wearable") { cflags_cc += [ "-DDYNAMIC_CLOSE_LIBS" ] } + + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } } diff --git a/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp b/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp index 7addfb80fca59b0c1726d44596d58682d9f38e73..121df383a956511c8fdd8df727e1269c3fac3b1c 100644 --- a/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp +++ b/services/accesstokenmanager/main/cpp/src/callback/accesstoken_callback_proxys.cpp @@ -36,6 +36,9 @@ PermissionStateChangeCallbackProxy::PermissionStateChangeCallbackProxy(const spt PermissionStateChangeCallbackProxy::~PermissionStateChangeCallbackProxy() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PermissionStateChangeCallbackProxy::PermStateChangeCallback(PermStateChangeInfo& result) { MessageParcel data; @@ -67,6 +70,9 @@ void PermissionStateChangeCallbackProxy::PermStateChangeCallback(PermStateChange LOGI(ATM_DOMAIN, ATM_TAG, "SendRequest success"); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif #ifdef TOKEN_SYNC_ENABLE TokenSyncCallbackProxy::TokenSyncCallbackProxy(const sptr& impl) @@ -76,6 +82,9 @@ TokenSyncCallbackProxy::TokenSyncCallbackProxy(const sptr& impl) TokenSyncCallbackProxy::~TokenSyncCallbackProxy() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif int32_t TokenSyncCallbackProxy::GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) { MessageParcel data; @@ -177,6 +186,9 @@ int32_t TokenSyncCallbackProxy::UpdateRemoteHapTokenInfo(const HapTokenInfoForSy LOGI(ATM_DOMAIN, ATM_TAG, "Get result from callback, data = %{public}d", result); return result; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif #endif // TOKEN_SYNC_ENABLE } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp index f13756be48d35cc2d04d19dd1e8505f798554d21..1ef18e189ab3907baf57fb5e03772f893df935d0 100644 --- a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp +++ b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp @@ -51,6 +51,9 @@ void ReportSysEventServiceStart(const AccessTokenDfxInfo& info) } } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void ReportSysEventServiceStartError(SceneCode scene, const std::string& errMsg, int32_t errCode) { int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "ACCESSTOKEN_SERVICE_START_ERROR", @@ -59,6 +62,9 @@ void ReportSysEventServiceStartError(SceneCode scene, const std::string& errMsg, LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", ret); } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif void ReportSysCommonEventError(int32_t ipcCode, int32_t errCode) { diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp index 941fafe1fd691661ef23e4a5ee0af2406eab38a2..7be446082188646779ca6b4032cb4fa18759b00f 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_validator.cpp @@ -25,10 +25,16 @@ namespace OHOS { namespace Security { namespace AccessToken { +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif bool PermissionValidator::IsGrantModeValid(int grantMode) { return grantMode == GrantMode::SYSTEM_GRANT || grantMode == GrantMode::USER_GRANT; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif bool PermissionValidator::IsGrantStatusValid(int grantStatus) { @@ -55,6 +61,9 @@ bool PermissionValidator::IsToggleStatusValid(const uint32_t status) return DataValidator::IsToggleStatusValid(status); } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif bool PermissionValidator::IsPermissionDefValid(const PermissionDef& permDef) { if (!DataValidator::IsLabelValid(permDef.label)) { @@ -87,6 +96,9 @@ bool PermissionValidator::IsPermissionDefValid(const PermissionDef& permDef) } return true; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif bool PermissionValidator::IsPermissionAvailable(ATokenTypeEnum tokenType, const std::string& permissionName) { @@ -113,6 +125,9 @@ bool PermissionValidator::IsPermissionStateValid(const PermissionStatus& permSta return true; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PermissionValidator::FilterInvalidPermissionDef( const std::vector& permList, std::vector& result) { @@ -126,6 +141,9 @@ void PermissionValidator::FilterInvalidPermissionDef( result.emplace_back(*it); } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif void PermissionValidator::FilterInvalidPermissionState(ATokenTypeEnum tokenType, bool doPermAvailableCheck, const std::vector& permList, std::vector& result) diff --git a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp index 66554b8e72a38df66e3eef04d28b8d6ccb19673c..82d701e2b411c2327a5b818b977effc0fb5f2e35 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp @@ -49,6 +49,9 @@ ShortGrantManager& ShortGrantManager::GetInstance() return *instance; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void ShortPermAppManagerDeathCallback::NotifyAppManagerDeath() { LOGI(ATM_DOMAIN, ATM_TAG, "ShortGrantManager AppManagerDeath called"); @@ -89,6 +92,9 @@ ShortGrantManager::~ShortGrantManager() { UnRegisterAppStopListener(); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif #ifdef EVENTHANDLER_ENABLE void ShortGrantManager::InitEventHandler() @@ -184,6 +190,9 @@ int ShortGrantManager::RefreshPermission(AccessTokenID tokenID, const std::strin return RET_SUCCESS; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void ShortGrantManager::ClearShortPermissionData(AccessTokenID tokenID, const std::string& permission) { std::unique_lock lck(shortGrantDataMutex_); @@ -314,6 +323,9 @@ void ShortGrantManager::UnRegisterAppStopListener() appStopCallBack_= nullptr; } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif ShortGrantManager::ShortGrantManager() : maxTime_(DEFAULT_MAX_TIME_MILLISECONDS) {} diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index b4a33356047cd9b48c668bbafadaa14e6324fd30..a54c6f9366d0046a40a11648bd9f8fdd40287f6f 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -111,6 +111,9 @@ AccessTokenManagerService::~AccessTokenManagerService() LOGI(ATM_DOMAIN, ATM_TAG, "~AccessTokenManagerService()"); } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void AccessTokenManagerService::OnStart() { if (state_ == ServiceRunningState::STATE_RUNNING) { @@ -159,6 +162,9 @@ void AccessTokenManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, c return; } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int32_t AccessTokenManagerService::GetPermissionUsedType( AccessTokenID tokenID, const std::string& permissionName, int32_t& permUsedType) @@ -1252,6 +1258,9 @@ int32_t AccessTokenManagerService::ClearUserPolicy() return AccessTokenInfoManager::GetInstance().ClearUserPolicy(); } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif int AccessTokenManagerService::Dump(int fd, const std::vector& args) { if (fd < 0) { @@ -1286,6 +1295,9 @@ int AccessTokenManagerService::Dump(int fd, const std::vector& a } return ERR_OK; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif void AccessTokenManagerService::AccessTokenServiceParamSet() const { @@ -1302,6 +1314,9 @@ void AccessTokenManagerService::AccessTokenServiceParamSet() const } } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void AccessTokenManagerService::SetFlagIfNeed(const AccessTokenServiceConfig& atConfig, int32_t& cancelTime, uint32_t& parseConfigFlag) { @@ -1336,6 +1351,9 @@ void AccessTokenManagerService::SetFlagIfNeed(const AccessTokenServiceConfig& at parseConfigFlag |= 0x1 << BITMAP_INDEX_6; } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif void AccessTokenManagerService::GetConfigValue(uint32_t& parseConfigFlag) { diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 08003e2a99cc8023f9116ebccaad6051ffeae32f..4f44d3a8a271924aaf49544859b978702d6167bf 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -90,6 +90,9 @@ ohos_static_library("accesstoken_service_common") { cflags_cc += [ "-DCONFIG_USE_JEMALLOC_DFX_INTF" ] } } + if (use_libfuzzer) { + cflags_cc += [ "-DFUZZ_TEST" ] + } } group("accesstoken_common") { diff --git a/services/common/app_manager/src/app_manager_access_client.cpp b/services/common/app_manager/src/app_manager_access_client.cpp index 374f3e86d0d5400a3bbfeeb388e2dee38e49ccab..92fcbe7f8e244dcb38e1064e323ae6c76235b8f6 100644 --- a/services/common/app_manager/src/app_manager_access_client.cpp +++ b/services/common/app_manager/src/app_manager_access_client.cpp @@ -45,11 +45,17 @@ AppManagerAccessClient& AppManagerAccessClient::GetInstance() AppManagerAccessClient::AppManagerAccessClient() {} +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif AppManagerAccessClient::~AppManagerAccessClient() { std::lock_guard lock(proxyMutex_); ReleaseProxy(); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int32_t AppManagerAccessClient::RegisterApplicationStateObserver(const sptr& observer) { @@ -90,6 +96,9 @@ int32_t AppManagerAccessClient::RegisterApplicationStateObserver(const sptr &observer) { if (observer == nullptr) { @@ -157,6 +166,9 @@ int32_t AppManagerAccessClient::GetForegroundApplications(std::vector& callback) { std::lock_guard lock(deathCallbackMutex_); @@ -206,6 +221,9 @@ void AppManagerAccessClient::OnRemoteDiedHandle() ReleaseProxy(); } } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif sptr AppManagerAccessClient::GetProxy() { @@ -216,6 +234,9 @@ sptr AppManagerAccessClient::GetProxy() return proxy_; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void AppManagerAccessClient::ReleaseProxy() { if (proxy_ != nullptr && serviceDeathObserver_ != nullptr) { @@ -230,6 +251,9 @@ void AppManagerAccessClient::AppMgrDeathRecipient::OnRemoteDied(const wptr PrivacyManagerService::GetProxyDeathHandler() { std::lock_guard lock(deathHandlerMutex_); @@ -189,6 +198,9 @@ void PrivacyManagerService::ReleaseDeathStub(int32_t callerPid) } handler->ReleaseProxyByParam(param); } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif int32_t PrivacyManagerService::StartUsingPermission( const PermissionUsedTypeInfoParcel &infoParcel, const sptr& anonyStub) @@ -325,6 +337,9 @@ int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( IPCSkeleton::GetCallingTokenID(), permList, callback); } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif int32_t PrivacyManagerService::ResponseDumpCommand(int32_t fd, const std::vector& args) { if (args.size() < 2) { // 2 :need two args 0:command 1:tokenId @@ -391,6 +406,9 @@ int32_t PrivacyManagerService::Dump(int32_t fd, const std::vector& callback) { @@ -483,6 +501,9 @@ int32_t PrivacyManagerService::GetPermissionUsedTypeInfos(const AccessTokenID to return RET_SUCCESS; } +#ifdef FUZZ_TEST +// LCOV_EXCL_START +#endif void PrivacyManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { LOGI(PRI_DOMAIN, PRI_TAG, "saId is %{public}d", systemAbilityId); @@ -515,6 +536,9 @@ bool PrivacyManagerService::Initialize() ReportPrivacyUserData(); return true; } +#ifdef FUZZ_TEST +// LCOV_EXCL_STOP +#endif bool PrivacyManagerService::IsPrivilegedCalling() const { diff --git a/test/fuzztest/normalize_service/accesstoken/access_token_service_fuzz.gni b/test/fuzztest/normalize_service/accesstoken/access_token_service_fuzz.gni index 1fcbd5d358a96a44a636d13a5ecb36f08be3846a..e5e32d945fedb60107cc3aee902e5ccade4e4a21 100644 --- a/test/fuzztest/normalize_service/accesstoken/access_token_service_fuzz.gni +++ b/test/fuzztest/normalize_service/accesstoken/access_token_service_fuzz.gni @@ -179,3 +179,7 @@ if (memory_manager_enable == true) { access_token_cflags_cc += [ "-DMEMORY_MANAGER_ENABLE" ] access_token_external_deps += [ "memmgr:memmgrclient" ] } + +if (use_libfuzzer) { + access_token_cflags_cc += [ "-DFUZZ_TEST" ] +} diff --git a/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni b/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni index 97dd8f273efe24455f8fd1fa694434a8ce4e4545..0f08cbfd79bd1be7aa1076d0ec13112d7ac8829c 100644 --- a/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni +++ b/test/fuzztest/services/accesstoken/access_token_service_fuzz.gni @@ -179,3 +179,7 @@ if (memory_manager_enable == true) { access_token_cflags_cc += [ "-DMEMORY_MANAGER_ENABLE" ] access_token_external_deps += [ "memmgr:memmgrclient" ] } + +if (use_libfuzzer) { + access_token_cflags_cc += [ "-DFUZZ_TEST" ] +} diff --git a/test/fuzztest/services/privacy/privacy_service_fuzz.gni b/test/fuzztest/services/privacy/privacy_service_fuzz.gni index f833e86570a4e63666d1136821b757b948cf2307..bb076181a6f302cbf9b2c8c611b9c4517b2efa1d 100644 --- a/test/fuzztest/services/privacy/privacy_service_fuzz.gni +++ b/test/fuzztest/services/privacy/privacy_service_fuzz.gni @@ -149,3 +149,7 @@ if (camera_framework_enable) { privacy_cflags_cc += [ "-DCAMERA_FRAMEWORK_ENABLE" ] privacy_external_deps += [ "camera_framework:camera_framework" ] } + +if (use_libfuzzer) { + privacy_cflags_cc += [ "-DFUZZ_TEST" ] +}