ss_bsdiff: Fix to check the return value of lseek() 12/314612/3 accepted/tizen_unified_dev accepted/tizen/unified/20240718.143638 accepted/tizen/unified/dev/20240722.073439 accepted/tizen/unified/toolchain/20240812.133507 accepted/tizen/unified/x/20240719.012651 accepted/tizen/unified/x/asan/20240813.231950
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 16 Jul 2024 07:42:49 +0000 (16:42 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 16 Jul 2024 10:39:24 +0000 (19:39 +0900)
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 <sy.kwak@samsung.com>
bsdiff/ss_bsdiff.c

index 2bcc1a7a5f64e0edf308c7ea84522335ff539063..6a6422a9e9e019fc400db29087a175a637805d8b 100644 (file)
@@ -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;