From 8bd5744711f0cd05b05ea1713b8b4833d5fee3bd Mon Sep 17 00:00:00 2001 From: toolsmanhehe <1340909670@qq.com> Date: Wed, 15 Jul 2026 19:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E5=A7=8B=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=94=99=E8=AF=AF=E7=A0=81=E6=9C=AA=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: toolsmanhehe <1340909670@qq.com> --- .../include/bundle_ms_feature.h | 2 +- .../bundlemgr_lite/src/bundle_ms_feature.cpp | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/services/bundlemgr_lite/include/bundle_ms_feature.h b/services/bundlemgr_lite/include/bundle_ms_feature.h index 4769e31..6305744 100755 --- a/services/bundlemgr_lite/include/bundle_ms_feature.h +++ b/services/bundlemgr_lite/include/bundle_ms_feature.h @@ -64,7 +64,7 @@ private: static uint8_t GetInnerBundleSize(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t HandleGetBundleInfosByIndex(const uint8_t funcId, IpcIo *req, IpcIo *reply); static uint8_t HandleGetBundleInfosLength(const uint8_t funcId, IpcIo *req, IpcIo *reply); - static BundleInfo *GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32_t *length); + static BundleInfo *GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32_t *length, uint8_t *outErrorCode = nullptr); Identity identity_; static BundleInvokeType BundleMsInvokeFuc[BMS_INNER_BEGIN]; diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp index a26c874..5dca9bc 100644 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -558,10 +558,13 @@ uint8_t BundleMsFeature::GetBundleNameForUid(int32_t uid, char **bundleName) return OHOS_SUCCESS; } -BundleInfo *BundleMsFeature::GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32_t *length) +BundleInfo *BundleMsFeature::GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32_t *length, uint8_t *outErrorCode) { HILOG_INFO(HILOG_MODULE_APP, "BundleMS GetInnerBundleInfos start"); if ((req == nullptr) || (reply == nullptr)) { + if (outErrorCode != nullptr) { + *outErrorCode = ERR_APPEXECFWK_OBJECT_NULL; + } return nullptr; } BundleInfo *bundleInfos = nullptr; @@ -578,15 +581,24 @@ BundleInfo *BundleMsFeature::GetInnerBundleInfos(IpcIo *req, IpcIo *reply, int32 size_t len = 0; char *metaDataKey = reinterpret_cast(ReadString(req, &len)); if (metaDataKey == nullptr) { + if (outErrorCode != nullptr) { + *outErrorCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; + } return nullptr; } errorCode = GetBundleInfosByMetaData(metaDataKey, &bundleInfos, length); } else { + if (outErrorCode != nullptr) { + *outErrorCode = ERR_APPEXECFWK_COMMAND_ERROR; + } return nullptr; } if (errorCode != OHOS_SUCCESS) { HILOG_ERROR(HILOG_MODULE_APP, "BundleMS GetInnerBundleInfos failed with errorcode: %{public}d\n", errorCode); BundleInfoUtils::FreeBundleInfos(bundleInfos, *length); + if (outErrorCode != nullptr) { + *outErrorCode = errorCode; + } return nullptr; } HILOG_DEBUG(HILOG_MODULE_APP, "BundleMS GetInnerBundleInfos with length is: %{public}d\n", *length); @@ -600,10 +612,12 @@ uint8_t BundleMsFeature::HandleGetBundleInfosLength(const uint8_t funcId, IpcIo return ERR_APPEXECFWK_OBJECT_NULL; } int32_t lengthOfBundleInfo = 0; - BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo); + uint8_t errorCode = OHOS_SUCCESS; + BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo, &errorCode); if (bundleInfos == nullptr) { - HILOG_ERROR(HILOG_MODULE_APP, "BundleMS bundleInfos is nullptr"); - return ERR_APPEXECFWK_OBJECT_NULL; + HILOG_ERROR(HILOG_MODULE_APP, "BundleMS bundleInfos is nullptr, errorCode: %{public}d", errorCode); + WriteUint8(reply, errorCode); + return errorCode; } WriteUint8(reply, static_cast(OHOS_SUCCESS)); WriteInt32(reply, lengthOfBundleInfo); @@ -619,9 +633,20 @@ uint8_t BundleMsFeature::HandleGetBundleInfosByIndex(const uint8_t funcId, IpcIo return ERR_APPEXECFWK_OBJECT_NULL; } int32_t lengthOfBundleInfo = 0; - BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo); + uint8_t errorCode = OHOS_SUCCESS; + BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo, &errorCode); int32_t index = 0; ReadInt32(req, &index); + if (bundleInfos == nullptr) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleMS HandleGetBundleInfosByIndex bundleInfos is nullptr"); + return errorCode; + } + if (index < 0 || index >= lengthOfBundleInfo) { + HILOG_ERROR(HILOG_MODULE_APP, "BundleMS index out of range: %{public}d, length: %{public}d", + index, lengthOfBundleInfo); + BundleInfoUtils::FreeBundleInfos(bundleInfos, lengthOfBundleInfo); + return ERR_APPEXECFWK_COMMAND_ERROR; + } HILOG_INFO(HILOG_MODULE_APP, "BundleMS index is : %{public}d\n", index); char *str = ConvertUtils::ConvertBundleInfoToString(bundleInfos + index); if (str == nullptr) {