From 137b76fcdf770a6799782bdebed1e720ebaea780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Wed, 9 Jul 2025 17:32:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9json=20=E6=9C=AA?= =?UTF-8?q?=E9=87=8A=E6=94=BEjson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 I:# --- modules/sandbox/normal/sandbox_core.cpp | 27 +++++++++++-------- .../sandbox/normal/sandbox_shared_mount.cpp | 7 +++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 033213f9..2e28c99d 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -432,32 +432,37 @@ int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string } int ret = 0; cJSON *hspRoot = GetJsonObjFromProperty(appProperty, SandboxCommonDef::HSPLIST_SOCKET_TYPE.c_str()); - APPSPAWN_CHECK_ONLY_EXPER(hspRoot != nullptr && cJSON_IsObject(hspRoot), return 0); - + APPSPAWN_CHECK_ONLY_EXPER(hspRoot != nullptr, return 0); + APPSPAWN_CHECK_ONLY_EXPER(cJSON_IsObject(hspRoot), cJSON_Delete(hspRoot); return 0); cJSON *bundles = cJSON_GetObjectItemCaseSensitive(hspRoot, "bundles"); + APPSPAWN_CHECK(bundles != nullptr && cJSON_IsArray(bundles), cJSON_Delete(hspRoot); + return -1, "MountAllHsp: invalid bundles"); cJSON *modules = cJSON_GetObjectItemCaseSensitive(hspRoot, "modules"); + APPSPAWN_CHECK(modules != nullptr && cJSON_IsArray(modules), cJSON_Delete(hspRoot); + return -1, "MountAllHsp: invalid modules"); cJSON *versions = cJSON_GetObjectItemCaseSensitive(hspRoot, "versions"); - APPSPAWN_CHECK(bundles != nullptr && cJSON_IsArray(bundles), return -1, "MountAllHsp: invalid bundles"); - APPSPAWN_CHECK(modules != nullptr && cJSON_IsArray(modules), return -1, "MountAllHsp: invalid modules"); - APPSPAWN_CHECK(versions != nullptr && cJSON_IsArray(versions), return -1, "MountAllHsp: invalid versions"); + APPSPAWN_CHECK(versions != nullptr && cJSON_IsArray(versions), cJSON_Delete(hspRoot); + return -1, "MountAllHsp: invalid versions"); int count = cJSON_GetArraySize(bundles); - APPSPAWN_CHECK(count == cJSON_GetArraySize(modules), return -1, "MountAllHsp: sizes are not same"); - APPSPAWN_CHECK(count == cJSON_GetArraySize(versions), return -1, "MountAllHsp: sizes are not same"); + APPSPAWN_CHECK(count == cJSON_GetArraySize(modules), cJSON_Delete(hspRoot); + return -1, "MountAllHsp: sizes are not same"); + APPSPAWN_CHECK(count == cJSON_GetArraySize(versions), cJSON_Delete(hspRoot); + return -1, "MountAllHsp: sizes are not same"); APPSPAWN_LOGI("MountAllHsp app: %{public}s, count: %{public}d", GetBundleName(appProperty), count); for (int i = 0; i < count; i++) { if (!(cJSON_IsString(cJSON_GetArrayItem(bundles, i)) && cJSON_IsString(cJSON_GetArrayItem(modules, i)) && cJSON_IsString(cJSON_GetArrayItem(versions, i)))) { + cJSON_Delete(hspRoot); return -1; } const char *libBundleName = cJSON_GetStringValue(cJSON_GetArrayItem(bundles, i)); const char *libModuleName = cJSON_GetStringValue(cJSON_GetArrayItem(modules, i)); const char *libVersion = cJSON_GetStringValue(cJSON_GetArrayItem(versions, i)); APPSPAWN_CHECK(libBundleName != nullptr && libModuleName != nullptr && libVersion != nullptr, - return -1, "MountAllHsp: config error"); + cJSON_Delete(hspRoot); return -1, "MountAllHsp: config error"); APPSPAWN_CHECK(CheckPath(libBundleName) && CheckPath(libModuleName) && CheckPath(libVersion), - return -1, "MountAllHsp: path error"); - + cJSON_Delete(hspRoot); return -1, "MountAllHsp: path error"); std::string libPhysicalPath = SandboxCommonDef::g_physicalAppInstallPath + libBundleName + "/" + libVersion + "/" + libModuleName; std::string mntPath = @@ -467,7 +472,7 @@ int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string .destPath = mntPath.c_str() }; ret = SandboxCommon::DoAppSandboxMountOnce(appProperty, &arg); - APPSPAWN_CHECK(ret == 0, return 0, "mount library failed %{public}d", ret); + APPSPAWN_CHECK(ret == 0, cJSON_Delete(hspRoot); return 0, "mount library failed %{public}d", ret); } cJSON_Delete(hspRoot); return 0; diff --git a/modules/sandbox/normal/sandbox_shared_mount.cpp b/modules/sandbox/normal/sandbox_shared_mount.cpp index fe9f1453..63a02377 100644 --- a/modules/sandbox/normal/sandbox_shared_mount.cpp +++ b/modules/sandbox/normal/sandbox_shared_mount.cpp @@ -489,10 +489,9 @@ static int ParseDataGroupList(AppSpawnMgr *content, const AppSpawningCtx *proper { int ret = 0; cJSON *dataGroupList = GetJsonObjFromExtInfo(property, DATA_GROUP_SOCKET_TYPE); - if (dataGroupList == nullptr || !cJSON_IsArray(dataGroupList)) { - APPSPAWN_LOGE("dataGroupList is empty"); - return APPSPAWN_ARG_INVALID; - } + APPSPAWN_CHECK(dataGroupList != nullptr, return APPSPAWN_ARG_INVALID, "dataGroupList is empty"); + APPSPAWN_CHECK(cJSON_IsArray(dataGroupList), cJSON_Delete(dataGroupList); + return APPSPAWN_ARG_INVALID, "dataGroupList is not Array"); // Iterate through the array (assuming groups is an array) cJSON *item = nullptr; -- Gitee