fix Tizen_4.0_Migration_Weakness 16/139416/2
authorJeesun Kim <iamjs.kim@samsung.com>
Wed, 19 Jul 2017 01:53:24 +0000 (10:53 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Wed, 19 Jul 2017 02:16:45 +0000 (11:16 +0900)
Change-Id: I7ed12794ae31f5f6dd374f88a95685f6e1df1cab

server/cal_server_contacts.c
server/db/cal_db_plugin_event.c

index 721f66d..7b31353 100644 (file)
@@ -399,13 +399,14 @@ static void _cal_server_contacts_get_event_list(contacts_list_h contacts_list,
                        /* LCOV_EXCL_STOP */
                }
 
-               if (0 < delete_count) {
-                       DBG("delete_count");
-                       if (NULL == array)
-                               array = calloc(delete_count, sizeof(int));
-                       else
-                               array = realloc(array, (count +delete_count) *sizeof(int));
+               if (delete_count <= 0) {
+                       free(delete_array);
+                       continue;
+               }
 
+               DBG("delete_count");
+               if (NULL == array) {
+                       array = calloc(delete_count, sizeof(int));
                        if (NULL == array) {
                                /* LCOV_EXCL_START */
                                ERR("calloc() Fail");
@@ -413,11 +414,23 @@ static void _cal_server_contacts_get_event_list(contacts_list_h contacts_list,
                                break;
                                /* LCOV_EXCL_STOP */
                        }
-                       memcpy(array +count, delete_array, delete_count *sizeof(int));
-                       count += delete_count;
+               } else {
+                       int *realloc_array = NULL;
+                       realloc_array = realloc(array, (count +delete_count) *sizeof(int));
+                       if (NULL == realloc_array) {
+                               /* LCOV_EXCL_START */
+                               ERR("realloc() Fail");
+                               free(delete_array);
+                               break;
+                               /* LCOV_EXCL_STOP */
+                       }
+                       array = realloc_array;
                }
+               memcpy(array +count, delete_array, delete_count *sizeof(int));
+               count += delete_count;
                free(delete_array);
        } while (CONTACTS_ERROR_NONE == contacts_list_next(contacts_list));
+
        *out_delete = array;
        *out_count = count;
 }
index 45a1b7c..3fe6608 100644 (file)
@@ -2641,6 +2641,12 @@ static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_
                t_inserted = g_strsplit_set(inserted_exdate, " ,", -1);
                len_inserted = g_strv_length(t_inserted);
        }
+       if (len_inserted <= 0) {
+               ERR("len_inserted is 0");
+               g_strfreev(t_inserted);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
        if (NULL != original_exdate && '\0' != *original_exdate) {
                t_original = g_strsplit_set(original_exdate, " ,", -1);
                len_original = g_strv_length(t_original);