Fix SVACE issues
authorAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 29 Nov 2024 13:06:48 +0000 (14:06 +0100)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Fri, 29 Nov 2024 14:47:48 +0000 (15:47 +0100)
WID: 12150987 Unsafe conversion of expression 'dwPosition' with type
'SS-UINT32' to type __off64_t.

Change-Id: Ie1fbc1222bc238665ce3767f2909949a2c316177

src/upgrade-apply-deltafs/engine/SS_FSUpdate.c

index db4b661dec304e224d322fd7edcf21f8cdde97d8..6ecdf6d7b4948489f86334fb9d8156f7ffc20414 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <strings.h>
 #include <sys/wait.h>
+#include <stdint.h>
 
 #include <ftw.h>
 #include <sys/xattr.h>
@@ -385,8 +386,12 @@ SS_WriteFile(long wHandle,
 
        LOGL(LOG_SSENGINE, "Handle:%ld , Pos:%u , Size: %u\n", wHandle,
                        dwPosition, dwSize);
-
-       ret = lseek(wHandle, dwPosition, SEEK_SET);
+       if (dwPosition > INT64_MAX) {
+               LOGE("Position value exceeds 64-bit signed range: %u", dwPosition);
+               return E_SS_WRITE_ERROR;
+       }
+       __off64_t position = (__off64_t)dwPosition;
+       ret = lseek(wHandle, position, SEEK_SET);
        if (ret < 0) {
                LOGE(" lseek failed with return value: %d\n", ret);
                LOGL(LOG_SSENGINE, "lseek errno=%d\n", errno);
@@ -469,7 +474,12 @@ SS_ReadFile(long wHandle,
        LOG(" %s: Handle:%ld , Pos:%u , Size: %u", __func__, wHandle,
               dwPosition, dwSize);
 #endif
-       ret = lseek(wHandle, dwPosition, SEEK_SET);
+       if (dwPosition > INT64_MAX) {
+               LOGE("Position value exceeds 64-bit signed range: %u", dwPosition);
+               return E_SS_WRITE_ERROR;
+       }
+       __off64_t position = (__off64_t)dwPosition;
+       ret = lseek(wHandle, position, SEEK_SET);
        if (ret < 0) {
                LOGE("Handle:%ld , Pos:%u , Size: %u\n", wHandle, dwPosition,
                     dwSize);