diff --git a/frameworks/bundle_lite/src/bundle_manager.cpp b/frameworks/bundle_lite/src/bundle_manager.cpp index 50be38de30d6d614ea14ba4ef519e43747c7e0e7..205080d7469621973727cf84ece85a3a29531d6e 100644 --- a/frameworks/bundle_lite/src/bundle_manager.cpp +++ b/frameworks/bundle_lite/src/bundle_manager.cpp @@ -172,7 +172,7 @@ static uint8_t DeserializeInnerBundleName(IOwner owner, IpcIo *reply) info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } - if (length < 0 || length > MAX_BUNDLE_NAME) { + if (length > MAX_BUNDLE_NAME) { info->resultCode = ERR_APPEXECFWK_DESERIALIZATION_FAILED; return ERR_APPEXECFWK_DESERIALIZATION_FAILED; } @@ -599,7 +599,8 @@ static uint8_t ObtainBundleInfosOneByOne(BasicInfo basicInfo, int32_t len, uint8 WriteInt32(&innerIpcIo, i); ResultOfGetBundleInfo resultOfGetBundleInfo; resultOfGetBundleInfo.bundleInfo = nullptr; - int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_INFO_BY_INDEX, &innerIpcIo, &resultOfGetBundleInfo, Notify); + int32_t ret = bmsClient->Invoke(bmsClient, GET_BUNDLE_INFO_BY_INDEX, &innerIpcIo, + &resultOfGetBundleInfo, Notify); if (ret != OHOS_SUCCESS) { HILOG_ERROR(HILOG_MODULE_APP, "BundleManager ObtainBundleInfosOneByOne invoke failed: %{public}d\n", ret); return ERR_APPEXECFWK_INVOKE_ERROR; diff --git a/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h b/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h index 1e620342f26a98f253602484a3448e851733a5dc..738943db0c0c95f2d46d1bb68360198e7cf1f565 100644 --- a/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h +++ b/services/bundlemgr_lite/bundle_daemon/include/bundle_file_utils.h @@ -29,6 +29,7 @@ const char PATH_SEPARATOR = '/'; class BundleFileUtils : public NoCopyable { public: static bool MkRecursiveDir(const char *dir, bool isReadOthers); + static bool MkOwnerDir(const char *dir); static bool IsExistDir(const char *path); static bool IsExistFile(const char *file); static bool RemoveFile(const char *path); diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp index 3e6b6f7803dcb0b4bd4bd102bf72b7bced1e70f8..9e36b5b5fd2a859758573ff2d543e6df025c2389 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon.cpp @@ -200,7 +200,7 @@ int32_t BundleDaemon::CreateDataDirectoryInvoke(IpcIo *req) ReadInt32(req, &gid); bool isChown; ReadBool(req, &isChown); - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); return BundleDaemon::GetInstance().handler_.CreateDataDirectory(dataPath, uid, gid, isChown); } diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp index b48b4982565925b25abe4cf9272e42348ac1d9fd..efd972a25da9ffb9eb022642093b1150bd6c4c7f 100755 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_daemon_handler.cpp @@ -140,12 +140,12 @@ int32_t BundleDaemonHandler::CreateDataDirectory(const char *dataPath, int32_t u } if (!BundleFileUtils::IsExistDir(dataDir.c_str())) { - if (!BundleFileUtils::MkRecursiveDir(dataDir.c_str(), false)) { + if (!BundleFileUtils::MkOwnerDir(dataDir.c_str())) { PRINTE("BundleDaemonHandler", "create dataPath fail"); return EC_NODIR; } } - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); if (isChown && !BundleFileUtils::ChownFile(dataDir.c_str(), uid, gid)) { PRINTE("BundleDaemonHandler", "chown file fail"); return EC_NOFILE; diff --git a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp index 95e7ad34f0a9c150a0d5a987738c672c0382ca49..68474db63c179b19256c17c3823fc538728d68cf 100644 --- a/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp +++ b/services/bundlemgr_lite/bundle_daemon/src/bundle_file_utils.cpp @@ -78,6 +78,32 @@ bool BundleFileUtils::MkRecursiveDir(const char *dir, bool isReadOthers) return true; } +bool BundleFileUtils::MkOwnerDir(const char *dir) +{ + if (dir == nullptr) { + return false; + } + if (IsExistDir(dir)) { + return true; + } + size_t len = strlen(dir); + if (len == 0 || len > PATH_MAX) { + return false; + } + // Create directories level by level + char rootDir[PATH_MAX] = { '\0' }; + for (size_t i = 0; i < len; ++i) { + rootDir[i] = dir[i]; + if ((rootDir[i] == PATH_SEPARATOR || i == (len - 1)) && !IsExistDir(rootDir)) { + mode_t mode = S_IRWXU | S_IRWXG; + if (mkdir(rootDir, mode) < 0) { + return false; + } + } + } + return true; +} + bool BundleFileUtils::RemoveFile(const char *path) { if (IsExistFile(path)) { diff --git a/services/bundlemgr_lite/src/bundle_daemon_client.cpp b/services/bundlemgr_lite/src/bundle_daemon_client.cpp index 140ac1be1177d8216d190cf09fda606ad62b5189..9c2d38b35862f71308ac2b2167b4d29da5c399db 100644 --- a/services/bundlemgr_lite/src/bundle_daemon_client.cpp +++ b/services/bundlemgr_lite/src/bundle_daemon_client.cpp @@ -283,7 +283,7 @@ int32_t BundleDaemonClient::CreateDataDirectory(const char *dataPath, int32_t ui WriteInt32(&request, uid); WriteInt32(&request, gid); WriteBool(&request, isChown); - + PRINTI("BundleDaemonClient", "uid is %{public}d, isChown is %{public}d", uid, isChown); Lock lock(mutex_); #ifdef __LINUX__ return WaitResultSync(bdsClient_->Invoke(bdsClient_, CREATE_DATA_DIRECTORY, &request, this, Notify)); diff --git a/services/bundlemgr_lite/src/bundle_installer.cpp b/services/bundlemgr_lite/src/bundle_installer.cpp index c902c12f7e452d9864a99c5ec183b8b2dab9d12e..c401c5d735698158d1a43e362ec9a7624e6cc55a 100755 --- a/services/bundlemgr_lite/src/bundle_installer.cpp +++ b/services/bundlemgr_lite/src/bundle_installer.cpp @@ -330,13 +330,10 @@ bool BundleInstaller::MatchPermissions(const std::vector & restrict int32_t size = realRestrictedPermissions.size(); for (int32_t i = 0; i < size; i++) { - bool isMatched = false; - for (const auto & restrictedPermission : restrictedPermissions) { - if (realRestrictedPermissions[i] == restrictedPermission) { - isMatched = true; - break; - } - } + bool isMatched = std::any_of(restrictedPermissions.begin(), restrictedPermissions.end(), + [realRestrictedPermissions, i](const auto & restrictedPermission)->bool { + return realRestrictedPermissions[i] == restrictedPermission; + }); if (!isMatched) { HILOG_WARN(HILOG_MODULE_APP, "provisionPermissions is not match the bundle reqPermissions!"); return false; diff --git a/services/bundlemgr_lite/src/bundle_manager_service.cpp b/services/bundlemgr_lite/src/bundle_manager_service.cpp index fd5bf03e648dce27994dd644fcd5806804913c21..8fab37213c353f00987b91d9d5c0065011430d9b 100644 --- a/services/bundlemgr_lite/src/bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/bundle_manager_service.cpp @@ -672,10 +672,9 @@ static int32_t GenerateInnerUid(std::map &innerMap, const std: } int32_t ret = 0; for (int32_t i = 0; i < innerMap.rbegin()->first; ++i) { - if (innerMap.find(i) == innerMap.end()) { - innerMap.emplace(i, bundleName); - ret = i + baseUid; - return ret; + auto res = innerMap.emplace(i, bundleName); + if (res.second) { + return i + baseUid; } } diff --git a/services/bundlemgr_lite/src/bundle_ms_feature.cpp b/services/bundlemgr_lite/src/bundle_ms_feature.cpp index 10f44ef9d1cbf34c946f73fa0e6064e5e817a4f4..a26c87441865df9c7e9d09ddcb3e5bb333860381 100644 --- a/services/bundlemgr_lite/src/bundle_ms_feature.cpp +++ b/services/bundlemgr_lite/src/bundle_ms_feature.cpp @@ -122,13 +122,6 @@ BOOL BundleMsFeature::OnFeatureMessage(Feature *feature, Request *request) return TRUE; } -static void InnerFreeDataBuff(void *ptr) -{ - if (ptr != nullptr) { - cJSON_free(ptr); - } -} - uint8_t BundleMsFeature::HasSystemCapability(const uint8_t funcId, IpcIo *req, IpcIo *reply) { if ((req == nullptr) || (reply == nullptr)) { @@ -626,7 +619,7 @@ uint8_t BundleMsFeature::HandleGetBundleInfosByIndex(const uint8_t funcId, IpcIo return ERR_APPEXECFWK_OBJECT_NULL; } int32_t lengthOfBundleInfo = 0; - BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo);; + BundleInfo *bundleInfos = GetInnerBundleInfos(req, reply, &lengthOfBundleInfo); int32_t index = 0; ReadInt32(req, &index); HILOG_INFO(HILOG_MODULE_APP, "BundleMS index is : %{public}d\n", index); diff --git a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp index 5a3f6eb19b891a4f23e6b172c6da907504c5e518..650e58bc07c9b5c24dc166b703bd69c924e5a78e 100755 --- a/services/bundlemgr_lite/src/gt_bundle_extractor.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_extractor.cpp @@ -109,7 +109,7 @@ char *GtBundleExtractor::ExtractHapProfile(int32_t fp, uint32_t totalFileSize) } int32_t fileNameLen = strlen(fileName); - if (pathLen == 0 && (fileName != nullptr && strcmp(fileName, PROFILE_NAME) == 0)) { + if (pathLen == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) { UI_Free(fileName); fileName = nullptr; fileData = reinterpret_cast(AdapterMalloc(fileSize * sizeof(char))); @@ -154,7 +154,7 @@ bool GtBundleExtractor::ExtractResourceFile(const char *path, int32_t fp, uint32 } int32_t fileNameLen = strlen(fileName); - if ((strlen(relativeFilePath) == 0 && (fileName != nullptr && strcmp(fileName, PROFILE_NAME) == 0)) || + if ((strlen(relativeFilePath) == 0 && (strcmp(fileName, PROFILE_NAME) == 0)) || !BundleUtil::StartWith(relativeFilePath, ASSET_JS_PATH)) { if (!GtExtractorUtil::HasWrittenFile(path, relativeFilePath, fileName, fp, fileSize)) { UI_Free(fileName); diff --git a/services/bundlemgr_lite/src/gt_bundle_installer.cpp b/services/bundlemgr_lite/src/gt_bundle_installer.cpp index 1c1bfb37dcccf0813d670e3aaddc4c4253e37c0d..3392dcefcf06c5a00600606e5158312488cbd45f 100755 --- a/services/bundlemgr_lite/src/gt_bundle_installer.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_installer.cpp @@ -109,8 +109,7 @@ uint8_t GtBundleInstaller::VerifySignature(const char *path, SignatureInfo &sign VerifyResult verifyResult; // verify signature (void) APPVERI_SetDebugMode(true); - int32_t ret = (bundleStyle == THIRD_APP_FLAG) ? APPVERI_AppVerify(path, &verifyResult) : - APPVERI_AppVerify(path, &verifyResult); + int32_t ret = APPVERI_AppVerify(path, &verifyResult); HILOG_INFO(HILOG_MODULE_AAFWK, "[BMS] APPVERI_AppVerify is %d", ret); uint8_t errorCode = SwitchErrorCode(ret); if (errorCode != ERR_OK) { @@ -523,9 +522,6 @@ uint8_t GtBundleInstaller::UpdateBundleInfo(uint8_t bundleStyle, uint32_t labelI if (bundleStyle == SYSTEM_APP_FLAG) { bundleInfo->isSystemApp = true; GtManagerService::GetInstance().AddBundleInfo(bundleInfo); - } else if (bundleStyle == THIRD_SYSTEM_APP_FLAG) { - bundleInfo->isSystemApp = false; - GtManagerService::GetInstance().AddBundleInfo(bundleInfo); } else { bundleInfo->isSystemApp = false; GtManagerService::GetInstance().AddBundleInfo(bundleInfo); diff --git a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp index d5bb5fcd218dd0f0cb09ed4ae624e236bac26bf5..2d35f6f829eb3a6b2458f3303bf78a8488202f1e 100755 --- a/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_manager_service.cpp @@ -317,6 +317,9 @@ void GtManagerService::InstallAllSystemBundle(InstallerCallback installerCallbac AppInfoList *currentNode = nullptr; AppInfoList *nextNode = nullptr; LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(currentNode, nextNode, &list->appDoubleList, AppInfoList, appDoubleList) { + if (currentNode == nullptr) { + return; + } if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) || (strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) { continue; @@ -411,10 +414,12 @@ void GtManagerService::RemoveSystemAppPathList(List *systemP for (auto node = systemPathList->Begin(); node != systemPathList->End(); node = node->next_) { ToBeInstalledApp *toBeInstalledApp = node->value_; - AdapterFree(toBeInstalledApp->installedPath); - AdapterFree(toBeInstalledApp->path); - AdapterFree(toBeInstalledApp->appId); - UI_Free(toBeInstalledApp); + if (toBeInstalledApp != nullptr) { + AdapterFree(toBeInstalledApp->installedPath); + AdapterFree(toBeInstalledApp->path); + AdapterFree(toBeInstalledApp->appId); + UI_Free(toBeInstalledApp); + } } } @@ -433,6 +438,9 @@ void GtManagerService::ScanSystemApp(const cJSON *uninstallRecord, ListappDoubleList, AppInfoList, appDoubleList) { + if (currentNode == nullptr) { + return; + } if ((strcmp(((AppInfoList *)currentNode)->filePath, ".") == 0) || (strcmp(((AppInfoList *)currentNode)->filePath, "..") == 0)) { continue; @@ -696,6 +704,9 @@ void GtManagerService::RemoveBundleResList(const char *bundleName) for (auto node = bundleResList_->Begin(); node != bundleResList_->End(); node = node->next_) { BundleRes *res = node->value_; + if (res == nullptr) { + return; + } if (res->bundleName != nullptr && strcmp(bundleName, res->bundleName) == 0) { AdapterFree(res->abilityRes); AdapterFree(res); @@ -997,6 +1008,9 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list) return; } char *fileName = reinterpret_cast(AdapterMalloc(MAX_NAME_LEN + 1)); + if (fileName == nullptr) { + return; + } while ((ent = readdir(dir)) != nullptr) { if (memset_s(fileName, MAX_NAME_LEN + 1, 0, MAX_NAME_LEN + 1) != EOK) { break; @@ -1029,6 +1043,7 @@ void GtManagerService::APP_QueryAppInfo(const char *appDir, AppInfoList *list) APP_InsertAppInfo(appPath, (AppInfoList *)&list->appDoubleList); AdapterFree(appPath); } + closedir(dir); AdapterFree(fileName); }