Fix coverity issue 47/224347/1 accepted/tizen/unified/20200211.055805 submit/tizen/20200210.061949
authorjiyong.min <jiyong.min@samsung.com>
Mon, 10 Feb 2020 04:30:09 +0000 (13:30 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 10 Feb 2020 04:55:23 +0000 (13:55 +0900)
 - Untrusted value as argument

Change-Id: I369d575a1299a0961ea9506fc42c552e71d48cab

bmp/mm_util_bmp.c
imgcv/test/mm_util_imgcv_testsuite.c
packaging/libmm-utility.spec

index 4ef1022..8288396 100755 (executable)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <glib.h>
 
 #include <libnsbmp.h>
 #include <bmpfile.h>
@@ -57,23 +58,23 @@ void __bitmap_destroy(void *bitmap)
        MMUTIL_SAFE_FREE(bitmap);
 }
 
-static unsigned char *__load_file(const char *path, size_t * data_size)
+static gboolean __load_file(const char *path, unsigned char **data, size_t * data_size)
 {
        FILE *fd;
        struct stat sb;
-       unsigned char *buffer;
+       void *buffer = NULL;
        size_t size;
        size_t n;
 
        if (MM_UTIL_ERROR_NONE != mm_util_safe_fopen(path, "rb", &fd)) {
                mm_util_error("mm_util_safe_fopen failed");
-               return NULL;
+               return FALSE;
        }
 
        if (stat(path, &sb)) {
                mm_util_error("file stat failed");
                mm_util_safe_fclose(fd);
-               return NULL;
+               return FALSE;
        }
        size = sb.st_size;
 
@@ -81,7 +82,7 @@ static unsigned char *__load_file(const char *path, size_t * data_size)
        if (!buffer) {
                mm_util_error("Unable to allocate %lld bytes", (long long)size);
                mm_util_safe_fclose(fd);
-               return NULL;
+               return FALSE;
        }
 
        n = fread(buffer, 1, size, fd);
@@ -89,12 +90,14 @@ static unsigned char *__load_file(const char *path, size_t * data_size)
                mm_util_error("file read failed");
                MMUTIL_SAFE_FREE(buffer);
                mm_util_safe_fclose(fd);
-               return NULL;
+               return FALSE;
        }
 
        mm_util_safe_fclose(fd);
        *data_size = size;
-       return buffer;
+       *data = buffer;
+
+       return TRUE;
 }
 
 static void __print_error(const char *context, bmp_result code)
@@ -137,8 +140,7 @@ static int __read_bmp(const char *file_path, void *memory, size_t src_size, mm_u
 
        if (MMUTIL_STRING_VALID(file_path)) {
                mm_util_sec_debug("read from file [%s]", file_path);
-               data = __load_file(file_path, &size);
-               if (data == NULL)
+               if (!__load_file(file_path, &data, &size))
                        return MM_UTIL_ERROR_INVALID_OPERATION;
        } else {
                mm_util_debug("read from memory");
index e2fbf90..1fa7af4 100644 (file)
@@ -37,7 +37,7 @@ int main(int argc, char *argv[])
        unsigned char *img_buffer;
        size_t  img_buffer_size;
 
-       if (argc < 1) {
+       if (argc < 2) {
                fprintf(stderr, "Usage: ./mm_imgcv_testsuite filename(jpg format only)\n");
                return ret;
        }
index 766f2a5..547d3c5 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.1.36
+Version:    0.1.37
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0