From da4a9026c1838a9c8a39d28e14ca8d65feb8c092 Mon Sep 17 00:00:00 2001 From: chennuo Date: Tue, 15 Oct 2024 11:45:25 +0800 Subject: [PATCH] =?UTF-8?q?appspawn=E5=91=8A=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chennuo --- interfaces/innerkits/client/appspawn_client.c | 2 +- modules/sandbox/sandbox_utils.cpp | 13 +++++++------ service/hnp/base/hnp_json.c | 5 +++-- service/hnp/base/hnp_zip.c | 2 +- standard/appspawn_msgmgr.c | 4 ---- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/interfaces/innerkits/client/appspawn_client.c b/interfaces/innerkits/client/appspawn_client.c index ce1478cb..d2b42ccc 100644 --- a/interfaces/innerkits/client/appspawn_client.c +++ b/interfaces/innerkits/client/appspawn_client.c @@ -131,7 +131,7 @@ APPSPAWN_STATIC int CreateClientSocket(uint32_t type, uint32_t timeout) int pathLen = snprintf_s(addr.sun_path, pathSize, (pathSize - 1), "%s%s", APPSPAWN_SOCKET_DIR, socketName); APPSPAWN_CHECK(pathLen > 0, break, "Format path %{public}s error: %{public}d", socketName, errno); addr.sun_family = AF_LOCAL; - socklen_t socketAddrLen = (socklen_t)offsetof(struct sockaddr_un, sun_path) + pathLen + 1; + socklen_t socketAddrLen = (socklen_t)(offsetof(struct sockaddr_un, sun_path) + pathLen + 1); ret = connect(socketFd, (struct sockaddr *)(&addr), socketAddrLen); APPSPAWN_CHECK(ret == 0, break, "Failed to connect %{public}s error: %{public}d", addr.sun_path, errno); diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index e776277d..2ab19834 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1567,19 +1567,20 @@ static inline int EnableSandboxNamespace(AppSpawningCtx *appProperty, uint32_t s int32_t SandboxUtils::SetPermissionWithParam(AppSpawningCtx *appProperty) { - uint32_t index = 0; + int32_t index = 0; int32_t appFullMountStatus = CheckAppFullMountEnable(); if (appFullMountStatus == FILE_CROSS_APP_STATUS) { - index = (uint32_t)GetPermissionIndex(nullptr, FILE_CROSS_APP_MODE.c_str()); + index = GetPermissionIndex(nullptr, FILE_CROSS_APP_MODE.c_str()); } else if (appFullMountStatus == FILE_ACCESS_COMMON_DIR_STATUS) { - index = (uint32_t)GetPermissionIndex(nullptr, FILE_ACCESS_COMMON_DIR_MODE.c_str()); + index = GetPermissionIndex(nullptr, FILE_ACCESS_COMMON_DIR_MODE.c_str()); } - int32_t fileMgrIndex = GetPermissionIndex(nullptr, FILE_ACCESS_MANAGER_MODE.c_str()); - if (index > 0 && (CheckAppPermissionFlagSet(appProperty, static_cast(fileMgrIndex)) == 0)) { + int32_t fileMgrIndex = GetPermissionIndex(nullptr, FILE_ACCESS_MANAGER_MODE.c_str()); + if (index > 0 && fileMgrIndex > 0 && + (CheckAppPermissionFlagSet(appProperty, static_cast(fileMgrIndex)) == 0)) { return SetAppPermissionFlags(appProperty, index); } - return 0; + return -1; } int32_t SandboxUtils::SetAppSandboxProperty(AppSpawningCtx *appProperty, uint32_t sandboxNsFlags) diff --git a/service/hnp/base/hnp_json.c b/service/hnp/base/hnp_json.c index 6a807abc..fc386a82 100644 --- a/service/hnp/base/hnp_json.c +++ b/service/hnp/base/hnp_json.c @@ -257,10 +257,11 @@ static int HnpHapJsonWrite(cJSON *json) return HNP_ERRNO_BASE_FILE_OPEN_FAILED; } char *jsonStr = cJSON_Print(json); - size_t writeLen = fwrite(jsonStr, strlen(jsonStr), sizeof(char), fp); + size_t jsonStrSize = strlen(jsonStr); + size_t writeLen = fwrite(jsonStr, sizeof(char), jsonStrSize, fp); (void)fclose(fp); free(jsonStr); - if (writeLen == 0) { + if (writeLen != jsonStrSize) { HNP_LOGE("package info write file:%{public}s unsuccess!", HNP_PACKAGE_INFO_JSON_FILE_PATH); return HNP_ERRNO_BASE_FILE_WRITE_FAILED; } diff --git a/service/hnp/base/hnp_zip.c b/service/hnp/base/hnp_zip.c index 06db278f..937265b9 100644 --- a/service/hnp/base/hnp_zip.c +++ b/service/hnp/base/hnp_zip.c @@ -513,7 +513,7 @@ int HnpCfgGetFromZip(const char *inputFile, HnpCfgInfo *hnpCfg) return HNP_ERRNO_NOMEM; } int readSize = unzReadCurrentFile(zipFile, cfgStream, fileInfo.uncompressed_size); - if ((uLong)readSize != fileInfo.uncompressed_size) { + if (readSize < 0 || (uLong)readSize != fileInfo.uncompressed_size) { free(cfgStream); unzClose(zipFile); HNP_LOGE("unzip read zip:%{public}s info size[%{public}lu]=>[%{public}d] error!", inputFile, diff --git a/standard/appspawn_msgmgr.c b/standard/appspawn_msgmgr.c index 388d3edb..b720bb92 100644 --- a/standard/appspawn_msgmgr.c +++ b/standard/appspawn_msgmgr.c @@ -398,10 +398,6 @@ void DumpAppSpawnMsg(const AppSpawnMsgNode *message) AppSpawnMsgOwnerId *owner = (AppSpawnMsgOwnerId *)GetAppSpawnMsgInfo(message, TLV_OWNER_INFO); APPSPAWN_ONLY_EXPER(owner != NULL, APPSPAPWN_DUMP("App owner info: \"%{public}s\" ", owner->ownerId)); - AppSpawnMsgAccessToken *t = (AppSpawnMsgAccessToken *)GetAppSpawnMsgInfo(message, TLV_ACCESS_TOKEN_INFO); - APPSPAWN_ONLY_EXPER(t != NULL, - APPSPAPWN_DUMP("App access token info: %{private}" PRId64 "", t->accessTokenIdEx)); - AppSpawnMsgInternetInfo *info = (AppSpawnMsgInternetInfo *)GetAppSpawnMsgInfo(message, TLV_INTERNET_INFO); APPSPAWN_ONLY_EXPER(info != NULL, APPSPAPWN_DUMP("App internet permission info [%{public}d %{public}d]",