diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 033213f9fb6430879534efc26b45a07dbef45d4f..2e28c99daba9d54d8ddbcc390b9937d1dbf2e101 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 fe9f145350f5deb8a46f4ff859a19e5fbc693beb..63a023775d60d38b0c4fcb29105da543e48a4238 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;