upgrade-apply: Fix to check return value properly 52/315252/2
authorSangYoun Kwak <sy.kwak@samsung.com>
Mon, 29 Jul 2024 06:06:05 +0000 (15:06 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 30 Jul 2024 05:24:45 +0000 (14:24 +0900)
tar_block_read() function can return negative integer and it should be
handled properly. In the previous code, only '-1' and '0' cases are
handled but no negative values less than '-1'.

To fix this issue, negative values less than '-1' is also handled.

Change-Id: Ib3fd0478b008cbe298694ccc10ddf66cfbb7604e
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/upgrade-apply/main.c
src/upgrade-apply/patch/patch.c

index 5af3f4a69f0eb9207ae9e6844c5bf348b8660e21..da85dd81e2645895fd2d6bbd70b70d20ce96f352 100644 (file)
@@ -307,11 +307,13 @@ int apply_raw(const char *dest, TAR *tar)
        while (size > 0) {
                char buf[T_BLOCKSIZE];
                int r_read = tar_block_read(tar, buf);
-               switch (r_read) {
-               case -1:
+
+               if (r_read < 0) {
                        fprintf(stderr, "Couldn't read from the archive (errno: %m)\n");
                        return -1;
-               case 0:
+               }
+
+               if (r_read == 0) {
                        fprintf(stderr, "We have reached EOF unexpectedly\n");
                        return -1;
                }
index 9fac82ad6d752c500e07cc01999355b177aa3a09..d863880fb7741ec565ee0a607f38617567004071 100644 (file)
@@ -184,17 +184,17 @@ static size_t decompress_bytes(struct dec_funcs *funcs, struct bs_data *data, si
             }
 
             int r_read = tar_block_read(data->patch_tar, data->buff_in);
-            switch (r_read) {
-            case -1:
+
+            if (r_read < 0) {
                 fprintf(stderr, "Couldn't read from the archive (errno: %m)\n");
                 return PF_ERROR_DECOMPRESSION;
-            case 0:
+            }
+
+            if (r_read == 0) {
                 fprintf(stderr, "We have reached EOF unexpectedly\n");
                 return PF_ERROR_DECOMPRESSION;
             }
 
-                       assert(r_read >= 0);
-
             if ((size_t)r_read > data->patch_remaining) {
                 r_read = data->patch_remaining;
             }