default_backend: fix some svace issues 09/220709/1
authorjeon <jhyuni.kang@samsung.com>
Tue, 17 Sep 2019 12:51:17 +0000 (21:51 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 20 Dec 2019 09:56:14 +0000 (18:56 +0900)
Change-Id: I78fe3f4efc5723e93baf6227f9accb5a43d56f1a

backends/default_backend.c

index 390bfab..5d71cf2 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "default_backend.h"
+#include <limits.h>
 
 pui_backend_ani_func *ani_func = NULL;
 Eina_Hash *_animations_hash = NULL;
@@ -205,15 +206,17 @@ static char *
 _read_json_file(const char *path, int *data_size)
 {
        FILE *fp = fopen(path, "rb");
-       unsigned int size;
-       char *buffer;
+       int size;
+       char *buffer = NULL;
        ERROR_CHECK(fp, return NULL, "Failed to open file: %s\n", path);
 
        fseek(fp, 0, SEEK_END);
-       size = (unsigned int)ftell(fp);
+       size = (long int)ftell(fp);
        fseek(fp, 0, SEEK_SET);
+       ERROR_CHECK(0 < size && size < INT_MAX, goto error, "Invalid file: %d size\n", size);
 
        buffer = (char *)calloc(sizeof(char), size + 1);
+       ERROR_CHECK(buffer, goto error, "Failed to allocate memory for buffer\n");
 
        if (fread(buffer, size, 1, fp) < 1) {
                goto error;