From: SangYoun Kwak Date: Tue, 16 Jul 2024 07:42:49 +0000 (+0900) Subject: ss_bsdiff: Fix to check the return value of lseek() X-Git-Tag: accepted/tizen/unified/20240718.143638^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_unified_dev;p=platform%2Fcore%2Fsystem%2Fupgrade-tools.git ss_bsdiff: Fix to check the return value of lseek() To handle the lseek() failure case, codes for checking the return value of lseek() is added. Also, since the return value of lseek() is off_t, the type of its container is also modified to off_t. Change-Id: Ia7c63f3b5a4d4b306ff9a831584107007e32b140 Signed-off-by: SangYoun Kwak --- diff --git a/bsdiff/ss_bsdiff.c b/bsdiff/ss_bsdiff.c index 2bcc1a7..6a6422a 100644 --- a/bsdiff/ss_bsdiff.c +++ b/bsdiff/ss_bsdiff.c @@ -591,8 +591,16 @@ int PrintUserError(char *buffer, int buf_size) int brotli_compress_internal(int input_fd, int output_fd, int quality) { int res = -1; - size_t input_size = lseek(input_fd, 0, SEEK_END); - lseek(input_fd, 0, SEEK_SET); + off_t input_size = lseek(input_fd, 0, SEEK_END); + if (input_size < 0) { + printf("Can not get file size(lseek failed): %d - %m\n", errno); + return res; + } + + if (lseek(input_fd, 0, SEEK_SET) < 0) { + printf("Can not set file offset to the initial potition(lseek failed): %d - %m\n", errno); + return res; + } void *input_file_ptr = MAP_FAILED; void *output_file_ptr = MAP_FAILED;