mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2025-02-19 19:52:08 +00:00
hnp安装存在签名文件数量统计翻转的问题优化
Signed-off-by: 王达 <wangda20@huawei.com>
This commit is contained in:
parent
01b31d1e53
commit
a15f12db66
@ -18,7 +18,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@ -256,6 +255,9 @@ enum {
|
||||
// 0x80111f 获取文件属性失败
|
||||
#define HNP_ERRNO_BASE_STAT_FAILED HNP_ERRNO_COMMON(HNP_MID_BASE, 0x1f)
|
||||
|
||||
// 0x801120 二进制文件过多
|
||||
#define HNP_ERRNO_BASE_FILE_COUNT_OVER HNP_ERRNO_COMMON(HNP_MID_BASE, 0x20)
|
||||
|
||||
int GetFileSizeByHandle(FILE *file, int *size);
|
||||
|
||||
int ReadFileToStream(const char *filePath, char **stream, int *streamLen);
|
||||
@ -265,7 +267,7 @@ int GetRealPath(char *srcPath, char *realPath);
|
||||
int HnpZip(const char *inputDir, zipFile zf);
|
||||
|
||||
int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix,
|
||||
HnpSignMapInfo *hnpSignMapInfos, uint64_t *count);
|
||||
HnpSignMapInfo *hnpSignMapInfos, int *count);
|
||||
|
||||
int HnpAddFileToZip(zipFile zf, char *filename, char *buff, int size);
|
||||
|
||||
@ -298,7 +300,7 @@ int HnpPackageInfoDelete(const char *packageName);
|
||||
|
||||
char *HnpCurrentVersionUninstallCheck(const char *name);
|
||||
|
||||
int HnpFileCountGet(const char *path, uint64_t *count);
|
||||
int HnpFileCountGet(const char *path, int *count);
|
||||
|
||||
int HnpPathFileCount(const char *path);
|
||||
|
||||
|
@ -362,10 +362,10 @@ static bool HnpELFFileCheck(const char *path)
|
||||
}
|
||||
|
||||
static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, const char *value,
|
||||
HnpSignMapInfo *hnpSignMapInfos, uint64_t *count)
|
||||
HnpSignMapInfo *hnpSignMapInfos, int *count)
|
||||
{
|
||||
int ret;
|
||||
uint64_t sum = *count;
|
||||
int sum = *count;
|
||||
|
||||
if (HnpELFFileCheck(value) == false) {
|
||||
return 0;
|
||||
@ -387,9 +387,9 @@ static int HnpInstallAddSignMap(const char* hnpSignKeyPrefix, const char *key, c
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpFileCountGet(const char *path, uint64_t *count)
|
||||
int HnpFileCountGet(const char *path, int *count)
|
||||
{
|
||||
uint64_t sum = 0;
|
||||
int sum = 0;
|
||||
|
||||
unzFile zipFile = unzOpen(path);
|
||||
if (zipFile == NULL) {
|
||||
@ -399,6 +399,10 @@ int HnpFileCountGet(const char *path, uint64_t *count)
|
||||
|
||||
int ret = unzGoToFirstFile(zipFile);
|
||||
while (ret == UNZ_OK) {
|
||||
if (sum == INT_MAX) {
|
||||
unzClose(zipFile);
|
||||
return HNP_ERRNO_BASE_FILE_COUNT_OVER;
|
||||
}
|
||||
sum++;
|
||||
ret = unzGetCurrentFileInfo(zipFile, NULL, NULL, 0, NULL, 0, NULL, 0);
|
||||
if (ret != UNZ_OK) {
|
||||
@ -411,12 +415,15 @@ int HnpFileCountGet(const char *path, uint64_t *count)
|
||||
}
|
||||
|
||||
unzClose(zipFile);
|
||||
if (INT_MAX - sum < *count) {
|
||||
return HNP_ERRNO_BASE_FILE_COUNT_OVER;
|
||||
}
|
||||
*count += sum;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HnpUnZip(const char *inputFile, const char *outputDir, const char *hnpSignKeyPrefix,
|
||||
HnpSignMapInfo *hnpSignMapInfos, uint64_t *count)
|
||||
HnpSignMapInfo *hnpSignMapInfos, int *count)
|
||||
{
|
||||
char fileName[MAX_FILE_PATH_LEN];
|
||||
unz_file_info fileInfo;
|
||||
|
@ -43,9 +43,6 @@ extern "C" {
|
||||
// 0x801307 restorecon 安装目录失败
|
||||
#define HNP_ERRNO_INSTALLER_RESTORECON_HNP_PATH_FAIL HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x7)
|
||||
|
||||
// 0x801308 安装包中的二进制文件过多
|
||||
#define HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER HNP_ERRNO_COMMON(HNP_MID_INSTALLER, 0x8)
|
||||
|
||||
#define HNP_DEFAULT_INSTALL_ROOT_PATH "/data/app/el1/bundle"
|
||||
#define HNP_SANDBOX_BASE_PATH "/data/service/hnp"
|
||||
|
||||
|
@ -183,7 +183,7 @@ static int HnpGenerateSoftLink(const char *installPath, const char *hnpBasePath,
|
||||
}
|
||||
|
||||
static int HnpInstall(const char *hnpFile, HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg,
|
||||
HnpSignMapInfo *hnpSignMapInfos, uint64_t *count)
|
||||
HnpSignMapInfo *hnpSignMapInfos, int *count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -401,7 +401,7 @@ static int HnpPublicDealAfterInstall(HnpInstallInfo *hnpInfo, HnpCfgInfo *hnpCfg
|
||||
return HnpInstallInfoJsonWrite(hnpInfo->hapInstallInfo->hapPackageName, hnpCfg);
|
||||
}
|
||||
|
||||
static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, uint64_t *count)
|
||||
static int HnpReadAndInstall(char *srcFile, HnpInstallInfo *hnpInfo, HnpSignMapInfo *hnpSignMapInfos, int *count)
|
||||
{
|
||||
int ret;
|
||||
HnpCfgInfo hnpCfg = {0};
|
||||
@ -481,7 +481,7 @@ static bool HnpFileCheck(const char *file)
|
||||
}
|
||||
|
||||
static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo, char *sunDir,
|
||||
HnpSignMapInfo *hnpSignMapInfos, uint64_t *count)
|
||||
HnpSignMapInfo *hnpSignMapInfos, int *count)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
@ -537,7 +537,7 @@ static int HnpPackageGetAndInstall(const char *dirPath, HnpInstallInfo *hnpInfo,
|
||||
}
|
||||
|
||||
static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, HnpSignMapInfo *hnpSignMapInfos,
|
||||
uint64_t *count)
|
||||
int *count)
|
||||
{
|
||||
struct dirent *entry;
|
||||
char hnpPath[MAX_FILE_PATH_LEN];
|
||||
@ -585,7 +585,7 @@ static int HapReadAndInstall(const char *dstPath, HapInstallInfo *installInfo, H
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpInstallHnpFileCountGet(char *hnpPath, uint64_t *count)
|
||||
static int HnpInstallHnpFileCountGet(char *hnpPath, int *count)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
@ -636,7 +636,7 @@ static int HnpInstallHnpFileCountGet(char *hnpPath, uint64_t *count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HnpInstallHapFileCountGet(const char *root, uint64_t *count)
|
||||
static int HnpInstallHapFileCountGet(const char *root, int *count)
|
||||
{
|
||||
struct dirent *entry;
|
||||
char hnpPath[MAX_FILE_PATH_LEN];
|
||||
@ -714,11 +714,11 @@ static int CheckInstallPath(char *dstPath, HapInstallInfo *installInfo)
|
||||
static int HnpInsatllPre(HapInstallInfo *installInfo)
|
||||
{
|
||||
char dstPath[MAX_FILE_PATH_LEN];
|
||||
uint64_t count = 0;
|
||||
int count = 0;
|
||||
HnpSignMapInfo *hnpSignMapInfos = NULL;
|
||||
#ifdef CODE_SIGNATURE_ENABLE
|
||||
struct EntryMapEntryData data = {0};
|
||||
uint64_t i;
|
||||
int i;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
@ -727,9 +727,7 @@ static int HnpInsatllPre(HapInstallInfo *installInfo)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (count >= INT32_MAX) {
|
||||
return HNP_ERRNO_INSTALLER_HAP_FILE_COUNT_OVER;
|
||||
} else if (count > 0) {
|
||||
if (count > 0) {
|
||||
hnpSignMapInfos = (HnpSignMapInfo *)malloc(sizeof(HnpSignMapInfo) * count);
|
||||
if (hnpSignMapInfos == NULL) {
|
||||
return HNP_ERRNO_NOMEM;
|
||||
@ -738,8 +736,8 @@ static int HnpInsatllPre(HapInstallInfo *installInfo)
|
||||
|
||||
count = 0;
|
||||
ret = HapReadAndInstall(dstPath, installInfo, hnpSignMapInfos, &count);
|
||||
HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath,
|
||||
installInfo->abi, (int)count);
|
||||
HNP_LOGI("sign start hap path[%{public}s],abi[%{public}s],count=%{public}d", installInfo->hapPath, installInfo->abi,
|
||||
count);
|
||||
#ifdef CODE_SIGNATURE_ENABLE
|
||||
if ((ret == 0) && (count > 0)) {
|
||||
data.entries = malloc(sizeof(struct EntryMapEntry) * count);
|
||||
@ -751,7 +749,7 @@ static int HnpInsatllPre(HapInstallInfo *installInfo)
|
||||
data.entries[i].key = hnpSignMapInfos[i].key;
|
||||
data.entries[i].value = hnpSignMapInfos[i].value;
|
||||
}
|
||||
data.count = (uint32_t)count;
|
||||
data.count = count;
|
||||
ret = EnforceCodeSignForApp(installInfo->hapPath, &data, FILE_ENTRY_ONLY);
|
||||
HNP_LOGI("sign end ret=%{public}d,last key[%{public}s],value[%{public}s]", ret, data.entries[i - 1].key,
|
||||
data.entries[i - 1].value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user