diff options
author | shirsh-kumar <shirsh.kumar@samsung.com> | 2020-04-16 23:22:31 +0530 |
---|---|---|
committer | shirsh-kumar <shirsh.kumar@samsung.com> | 2020-04-20 11:36:23 +0530 |
commit | 1e860229374185e2e376486c93c64da91e1ced8c (patch) | |
tree | 1bccc41897ec0badfea8e78c978c944edc60cb05 | |
parent | d62d69108ae8c34b49a2a3cb03d314fbca675c9e (diff) | |
download | libtota-accepted/tizen_5.5_unified.tar.gz libtota-accepted/tizen_5.5_unified.tar.bz2 libtota-accepted/tizen_5.5_unified.zip |
Enable LONG file name support across all tar api's.submit/tizen_5.5_wearable_hotfix/20201026.184304submit/tizen_5.5/20200420.102457submit/tizen_5.5/20200420.080114accepted/tizen/5.5/unified/wearable/hotfix/20201027.113238accepted/tizen/5.5/unified/20200427.094513accepted/tizen/5.5/unified/20200420.142744tizen_5.5_wearable_hotfixtizen_5.5accepted/tizen_5.5_unified_wearable_hotfixaccepted/tizen_5.5_unified
Add additional info in error cases.
Fix crash issue in building cfg table for LONG file names.
Version up for Library
Change-Id: Id5ee04e95909833c29527bea689f9d138fdc54ed
Signed-off-by: shirsh-kumar <shirsh.kumar@samsung.com>
-rwxr-xr-x | ss_engine/fota_common.h | 2 | ||||
-rwxr-xr-x | ss_engine/fota_tar.c | 95 |
2 files changed, 84 insertions, 13 deletions
diff --git a/ss_engine/fota_common.h b/ss_engine/fota_common.h index 8213546..915a0e6 100755 --- a/ss_engine/fota_common.h +++ b/ss_engine/fota_common.h @@ -58,7 +58,7 @@ typedef unsigned long long u64; #define UNUSED(x) (void)(x) -#define SS_TOTA_VERSION "1.0.18" +#define SS_TOTA_VERSION "1.0.19" #define BSDIFF "BSDIFF40" #define IMGDIFF "IMGDIFF2" #define SECTOR_SIZE 512 diff --git a/ss_engine/fota_tar.c b/ss_engine/fota_tar.c index d5a7a99..b2592b2 100755 --- a/ss_engine/fota_tar.c +++ b/ss_engine/fota_tar.c @@ -194,7 +194,7 @@ int tar_get_item_offset(char *tar, char *item) int ret = -1; int fd = -1; char header[TAR_BLOCK_SIZE] = { 0, }; - char name[TAR_ITEM_NAME_SIZE + 1] = { 0, }; + char uExtendedName[MAX_FILE_PATH + 1] = { 0, }; char size_oct[TAR_SIZE_OF_HEADER] = { 0, }; unsigned long size_dec = 0; int blknum = 0; @@ -202,6 +202,10 @@ int tar_get_item_offset(char *tar, char *item) off_t tar_len = 0; ssize_t rdcnt = 0; + if (!item || !tar){ + LOG("Invalid params\n"); + return -1; + }; //check if gTarFd was opened by tar_open during SS_FSUpdateFile then use it if (gTarFd > 0) fd = gTarFd; @@ -232,16 +236,33 @@ int tar_get_item_offset(char *tar, char *item) } /* get file name and file size */ - memcpy(name, header, sizeof(name) - 1); + if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) { + //rdcnt = read(fd, header, sizeof(header)); + memset(uExtendedName, 0, sizeof(uExtendedName)); + rdcnt = read(fd, uExtendedName, sizeof(uExtendedName) - 1); + if (rdcnt <= 0) { + LOG("read failed. (rdcnt=%d)\n", rdcnt); + break; + } + rdcnt = read(fd, header, sizeof(header)); + if (rdcnt <= 0) { + LOG("read failed. (rdcnt=%d)\n", rdcnt); + break; + } + } else { + memset(uExtendedName, 0, sizeof(uExtendedName)); + memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE); + } memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct)); size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE); if (size_dec > MAX_ITEM_SIZE) { + LOG("ITEM : [%s]\n", item); LOG("size too big. (size_dec=0x%08X)\n", size_dec); break; } /* check if the file is what we are looking for */ - if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) { + if (strncmp(uExtendedName, item, sizeof(uExtendedName) - 1) == 0) { ret = (int)lseek(fd, 0, SEEK_CUR); break; } @@ -274,13 +295,18 @@ int tar_get_item_size(char *tar, char *item) int ret = -1; int fd = -1; char header[TAR_BLOCK_SIZE] = { 0, }; - char uExtendedName[MAX_FILE_PATH] = { 0, }; + char uExtendedName[MAX_FILE_PATH + 1] = { 0, }; char size_oct[TAR_SIZE_OF_HEADER] = { 0, }; unsigned long size_dec = 0; int blknum = 0; off_t pos = 0; off_t tar_len = 0; ssize_t rdcnt = 0; + + if (!item || !tar){ + LOG("Invalid params\n"); + return -1; + } LOGL(LOG_SSENGINE, "Tar file Looking for (%s)\n", item); fd = open(tar, O_RDONLY); if (fd < 0) { @@ -311,7 +337,7 @@ int tar_get_item_size(char *tar, char *item) if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) { //rdcnt = read(fd, header, sizeof(header)); memset(uExtendedName, 0, sizeof(uExtendedName)); - rdcnt = read(fd, uExtendedName, sizeof(uExtendedName)); + rdcnt = read(fd, uExtendedName, sizeof(uExtendedName) - 1); if (rdcnt <= 0) { LOG("read failed. (rdcnt=%d)\n", rdcnt); break; @@ -325,16 +351,16 @@ int tar_get_item_size(char *tar, char *item) memset(uExtendedName, 0, sizeof(uExtendedName)); memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE); } - //memcpy(name, header, sizeof(name)); memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct)); size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE); if (size_dec > MAX_ITEM_SIZE) { + LOG("ITEM : [%s]\n", item); LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec); break; } /* check if the file is what we are looking for */ - if (strcmp(uExtendedName, item) == 0) { + if (strncmp(uExtendedName, item, sizeof(uExtendedName) - 1) == 0) { ret = (int)size_dec; if ((ret == 0) && (header[TAR_ITEM_TYPE_FLAG_POS] == DIRTYPE)) ret = tar_get_folder_size(tar, item); @@ -369,13 +395,18 @@ char tar_get_item_type(char *tar, char *item) char ret = '0'; int fd = -1; char header[TAR_BLOCK_SIZE] = { 0, }; - char name[TAR_ITEM_NAME_SIZE + 1] = { 0, }; + char uExtendedName[MAX_FILE_PATH + 1] = { 0, }; char size_oct[TAR_SIZE_OF_HEADER] = { 0, }; unsigned long size_dec = 0; int blknum = 0; off_t pos = 0; off_t tar_len = 0; ssize_t rdcnt = 0; + + if (!item || !tar){ + LOG("Invalid params\n"); + return -1; + } //LOG("Tar file Looking for (%s)\n", item); fd = open(tar, O_RDONLY); if (fd < 0) { @@ -404,17 +435,34 @@ char tar_get_item_type(char *tar, char *item) } /* get file name and file size */ - memcpy(name, header, sizeof(name) - 1); + if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) { + //rdcnt = read(fd, header, sizeof(header)); + memset(uExtendedName, 0, sizeof(uExtendedName)); + rdcnt = read(fd, uExtendedName, sizeof(uExtendedName) - 1); + if (rdcnt <= 0) { + LOG("read failed. (rdcnt=%d)\n", rdcnt); + break; + } + rdcnt = read(fd, header, sizeof(header)); + if (rdcnt <= 0) { + LOG("read failed. (rdcnt=%d)\n", rdcnt); + break; + } + } else { + memset(uExtendedName, 0, sizeof(uExtendedName)); + memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE); + } memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct)); size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE); if (size_dec > MAX_ITEM_SIZE) { + LOG("ITEM : [%s]\n", item); LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec); ret = -1; break; } /* check if the file is what we are looking for */ - if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) { + if (strncmp(uExtendedName, item, sizeof(uExtendedName) - 1) == 0) { ret = header[TAR_ITEM_TYPE_FLAG_POS]; break; } @@ -449,6 +497,10 @@ int tar_get_cfg_data(char *tar, char *item, char *buf, int buflen) off_t pos = 0; ssize_t rdcnt = 0; + if (!buf){ + LOG("Invalid params\n"); + return -1; + } data_size = tar_get_item_size(tar, item); if (data_size <= 0) return -1; @@ -491,7 +543,7 @@ tar_Data_t *tar_build_cfg_table(char *tar) int fd = -1; int ret = 0; char header[TAR_BLOCK_SIZE] = { 0, }; - char uExtendedName[MAX_FILE_PATH] = { 0, }; + char uExtendedName[MAX_FILE_PATH + 1] = { 0, }; char size_oct[TAR_SIZE_OF_HEADER] = { 0, }; unsigned long size_dec = 0; int blknum = 0; @@ -537,7 +589,6 @@ tar_Data_t *tar_build_cfg_table(char *tar) break; } /* get file name and file size */ - //memcpy(name, header, sizeof(name)); if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) { //rdcnt = read(fd, header, sizeof(header)); memset(uExtendedName, 0, sizeof(uExtendedName)); @@ -560,6 +611,7 @@ tar_Data_t *tar_build_cfg_table(char *tar) memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct)); size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE); if (size_dec > MAX_ITEM_SIZE) { + LOG("uExtendedName is : [%s]\n", uExtendedName); LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec); ret = -1; break; @@ -740,6 +792,11 @@ int tar_get_folder_size(char *tar, char *item) off_t pos = 0; off_t tar_len = 0; ssize_t rdcnt = 0; + + if (!item || !tar){ + LOG("Invalid params\n"); + return -1; + } LOG("Tar folder Looking for (%s)\n", item); fd = open(tar, O_RDONLY); if (fd < 0) { @@ -825,6 +882,11 @@ int tar_extract_folder(char *tar, char *item, char *path) int getheader = 1; // Asuming initial header is TAR header char fullname[512] = { 0 }; int ret; + + if (!item || !tar || !path){ + LOG("Invalid params\n"); + return -1; + } LOG("Extracting Folder from %s %s to %s\n", tar, item, path); data_offset = tar_get_item_offset(tar, item); @@ -999,6 +1061,10 @@ int fast_tar_extract_file(char *tar, char *item, char *pathname, int size, int o char err_buf[256]; int fd2; + if (!item || !tar || !pathname){ + LOG("Invalid params\n"); + return -1; + } if (gTarFd > 0) fd = gTarFd; if (fd < 0) { @@ -1063,6 +1129,11 @@ int tar_extract_file(char *tar, char *item, char *pathname) char *buf = NULL; char err_buf[256]; int fd2; + + if (!item || !tar || !pathname){ + LOG("Invalid params\n"); + return -1; + } data_size = tar_get_item_size(tar, item); data_offset = tar_get_item_offset(tar, item); |