From 85cf91bb8f0b337490d4cb5a13a8a64bf8ea559c Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Thu, 11 Sep 2025 11:00:23 +0800 Subject: [PATCH] add string empty check Signed-off-by: lanhaoyu --- .../ani/bundle_manager/ani_bundle_manager.cpp | 34 ++++++++++++++++--- .../js/bundle_manager/bundle_manager_sync.cpp | 20 +++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp index 3a79760087..25c3510ae4 100644 --- a/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp +++ b/interfaces/kits/ani/bundle_manager/ani_bundle_manager.cpp @@ -588,11 +588,27 @@ static ani_string GetAbilityLabelNative(ani_env* env, return nullptr; } std::string abilityLabel; - ErrCode ret = iBundleMgr->GetAbilityLabel(bundleName, moduleName, abilityName, abilityLabel); + ErrCode ret = CommonFunc::ConvertErrCode( + iBundleMgr->GetAbilityLabel(bundleName, moduleName, abilityName, abilityLabel)); + if (ret == ERROR_PARAM_CHECK_ERROR) { + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } else if (moduleName.empty()) { + APP_LOGW("moduleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + return nullptr; + } else { + APP_LOGW("abilityName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_ABILITYNAME_EMPTY_ERROR); + return nullptr; + } + } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("GetAbilityLabel failed ret: %{public}d", ret); - BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + BusinessErrorAni::ThrowCommonError(env, ret, isSync ? GET_ABILITY_LABEL_SYNC : GET_ABILITY_LABEL, BUNDLE_PERMISSIONS); return nullptr; } @@ -711,10 +727,16 @@ static ani_string GetSpecifiedDistributionType(ani_env* env, ani_string aniBundl return nullptr; } std::string specifiedDistributionType; - ErrCode ret = iBundleMgr->GetSpecifiedDistributionType(bundleName, specifiedDistributionType); + ErrCode ret = CommonFunc::ConvertErrCode( + iBundleMgr->GetSpecifiedDistributionType(bundleName, specifiedDistributionType)); + if (ret == ERROR_PARAM_CHECK_ERROR && bundleName.empty()) { + APP_LOGE("bundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } if (ret != ERR_OK) { APP_LOGE("GetSpecifiedDistributionType failed ret: %{public}d", ret); - BusinessErrorAni::ThrowCommonError(env, CommonFunc::ConvertErrCode(ret), + BusinessErrorAni::ThrowCommonError(env, ret, RESOURCE_NAME_OF_GET_SPECIFIED_DISTRIBUTION_TYPE, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); return nullptr; } @@ -927,6 +949,10 @@ static void SetApplicationEnabledNative(ani_env* env, return; } ErrCode ret = BundleManagerHelper::InnerSetApplicationEnabled(bundleName, isEnable, appIndex); + if (ret == ERROR_PARAM_CHECK_ERROR && bundleName.empty()) { + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return; + } bool isSync = CommonFunAni::AniBooleanToBool(aniIsSync); if (ret != ERR_OK) { APP_LOGE("SetApplicationEnabled failed ret: %{public}d", ret); diff --git a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp index 3ae284ae5e..05f89342b2 100644 --- a/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp +++ b/interfaces/kits/js/bundle_manager/bundle_manager_sync.cpp @@ -126,6 +126,11 @@ napi_value SetApplicationEnabledSync(napi_env env, napi_callback_info info) BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return nullptr; } + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return nullptr; + } if (!CommonFunc::ParseBool(env, args[ARGS_POS_ONE], isEnable)) { APP_LOGE("parse isEnable failed"); BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, IS_ENABLE, TYPE_BOOLEAN); @@ -519,14 +524,29 @@ ErrCode ParamsProcessGetAbilityLabelSync(napi_env env, napi_callback_info info, BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (bundleName.empty()) { + APP_LOGW("bundleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_BUNDLENAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } if (!CommonFunc::ParseString(env, args[ARGS_POS_ONE], moduleName)) { BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, MODULE_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (moduleName.empty()) { + APP_LOGW("moduleName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_MODULENAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } if (!CommonFunc::ParseString(env, args[ARGS_POS_TWO], abilityName)) { BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, ABILITY_NAME, TYPE_STRING); return ERROR_PARAM_CHECK_ERROR; } + if (abilityName.empty()) { + APP_LOGW("abilityName is empty"); + BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, PARAM_ABILITYNAME_EMPTY_ERROR); + return ERROR_PARAM_CHECK_ERROR; + } } else { BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR); return ERROR_PARAM_CHECK_ERROR; -- Gitee