From c827705e518a57c5c7c6fa41e3c2147efc9a7127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E6=99=AF=E4=B9=90?= Date: Mon, 28 Jul 2025 19:24:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 樊景乐 --- modules/sandbox/normal/sandbox_core.cpp | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index ddeecf1b..22d9487d 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -430,32 +430,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 = @@ -465,7 +470,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; -- Gitee