Fix coverity issue 41/224641/2 accepted/tizen/unified/20200212.125721 submit/tizen/20200212.070853
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Wed, 12 Feb 2020 05:40:46 +0000 (14:40 +0900)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Wed, 12 Feb 2020 05:57:15 +0000 (14:57 +0900)
- initialize file.data with NULL
- make item_data and buf to null terminated
- initialize sha1_ctx_t message buffer with NULL

Change-Id: I885f12079525f6745f1ab1a78051790c90f5007d
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
ss_engine/SS_PatchDelta.c
ss_engine/SS_UPI.c
ss_engine/sha1.c

index a65ae7ce1254e205eb694cd20d17ca5af79a986a..9b4c7db2b567426aa2b243b7a68c534b785a5f9d 100755 (executable)
@@ -639,7 +639,7 @@ int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *
                goto Cleanup;
        }
        //read kernel delta header for  delta names and size
-       buf = SS_Malloc(SS_KERNEL_DELTA_HEADER);
+       buf = SS_Malloc(SS_KERNEL_DELTA_HEADER + 1);
        if (!buf) {//wgid: 13099
                LOGE("Failed to allocate memory\n");
                result = E_SS_MALLOC_ERROR;
@@ -648,6 +648,8 @@ int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *
        ssize_t bytes_read = fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
        if (bytes_read != SS_KERNEL_DELTA_HEADER)
                LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)SS_KERNEL_DELTA_HEADER);
+       buf[bytes_read] = '\0';
+
        magic = strtok_r(buf, ":", &saveptr);
        LOGL(LOG_SSENGINE, "magic: %s\n", magic);
        tok_buf = strtok_r(NULL, ":", &saveptr);
index 935906e4e0037b648e688e9e5879050f36f5e331..9c51ed3fc683058b0b525bcf33bbb31f4a1051fd 100755 (executable)
@@ -315,6 +315,7 @@ int SS_verify_DELTA_image(char *filename)
        long int udelta_size = 0;
        int ulResult = S_SS_SUCCESS;
 
+       file.data = NULL;
        if (stat(filename, &file.st) != 0) {
                strerror_r(errno, buf, sizeof(buf));
                LOGE("failed to stat \"%s\": %s\n", filename, buf);
@@ -1348,6 +1349,8 @@ int SS_FSSetAttributes(ua_dataSS_t * ua_dataSS)
                }
                return E_SS_FAILURE;
        }
+       item_data[read_data] = '\0';
+
        pline = strtok_r(item_data, "\n", &psaveptr);
        if (pline == NULL) {
                LOGL(LOG_SSENGINE, "No Attributes to SET as no lines in file\n");
index 91ef661d3f9af75d715d520f7b93df9e2820c9da..54d75a2b16d3596059b92222667061a383452d52 100755 (executable)
@@ -183,6 +183,7 @@ sha1_core(const uint32_t M[16], uint32_t hash_value[5]) {
 
 void
 sha1_init(sha1_ctx_t *ctx) {
+  int i;
 
   /* initialize state vector */
   ctx->H[0] = 0x67452301;
@@ -191,6 +192,10 @@ sha1_init(sha1_ctx_t *ctx) {
   ctx->H[3] = 0x10325476;
   ctx->H[4] = 0xc3d2e1f0;
 
+  for(i = 0; i < 16; i++) {
+    ctx->M[i] = 0;
+  }
+
   /* indicate that message buffer is empty */
   ctx->octets_in_buffer = 0;