Add null check when allocating memory 16/139116/2
authorjusung son <jusung07.son@samsung.com>
Mon, 17 Jul 2017 10:16:07 +0000 (19:16 +0900)
committerjusung son <jusung07.son@samsung.com>
Mon, 17 Jul 2017 10:41:42 +0000 (19:41 +0900)
Change-Id: Ifa10e7dfa9f01e57f8208401b601961a074417be
Signed-off-by: jusung son <jusung07.son@samsung.com>
src/data_control_internal.c
src/data_control_noti.c [changed mode: 0644->0755]
src/data_control_provider.c
src/data_control_sql.c

index 4ebac505ddbf8d9f4315ceac77a91c9bbdfc804e..46a3c0bd1131d58f112fe7aae68c2e4726afda5e 100755 (executable)
@@ -137,6 +137,10 @@ static void __insert_hash(GHashTable *hash, const char *key,
 
        cert_info = (struct datacontrol_cert_info *)calloc(1,
                        sizeof(struct datacontrol_cert_info));
+       if (cert_info == NULL) {
+               _LOGE("out of memory.");
+               return;
+       }
 
        if (is_map)
                cert_info->map = status;
@@ -1500,6 +1504,11 @@ int _request_provider(data_control_h provider, datacontrol_request_type type,
        datacontrol_consumer_request_info *request_info =
                (datacontrol_consumer_request_info *)calloc(
                                sizeof(datacontrol_consumer_request_info), 1);
+       if (request_info == NULL) {
+               _LOGE("out of memory.");
+               return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+       }
+
        request_info->request_id = request_id;
        request_info->type = type;
        _dc_returned->request_info_list =
@@ -1787,15 +1796,15 @@ char *_get_encoded_db_path()
 char *_get_encoded_path(data_control_h provider, char *consumer_appid)
 {
        int prefix_len = strlen(DATA_CONTROL_DBUS_PATH_PREFIX);
-       char *encoded_path;
-       char *full_path;
+       char *encoded_path = NULL;
+       char *full_path = NULL;
        int path_len = strlen(provider->provider_id) +
                strlen(provider->data_id) + strlen(consumer_appid) + 3;
        int full_path_len = path_len + prefix_len;
        char *path = (char *)calloc(path_len, sizeof(char));
        if (path == NULL) {
                _LOGE("path calloc failed");
-               return 0;
+               return NULL;
        }
 
        snprintf(path, path_len, "%s_%s_%s", provider->provider_id,
@@ -1803,11 +1812,18 @@ char *_get_encoded_path(data_control_h provider, char *consumer_appid)
        encoded_path = g_compute_checksum_for_string(G_CHECKSUM_MD5, path, -1);
 
        full_path = (char *)calloc(full_path_len, sizeof(char));
+       if (full_path == NULL) {
+               _LOGE("out of memory.");
+               goto out;
+       }
+
        snprintf(full_path, full_path_len, "%s%s",
                        DATA_CONTROL_DBUS_PATH_PREFIX, encoded_path);
-
-       free(path);
-       free(encoded_path);
+out:
+       if (path)
+               free(path);
+       if (encoded_path)
+               free(encoded_path);
        _LOGI("full path : %s ", full_path);
        return full_path;
 }
old mode 100644 (file)
new mode 100755 (executable)
index f13ed3a..f259f25
@@ -417,6 +417,11 @@ EXPORT_API int data_control_add_data_change_cb(
 
        result_cb_info =
                (add_callback_result_cb_info_s *)calloc(1, sizeof(add_callback_result_cb_info_s));
+       if (result_cb_info == NULL) {
+               _LOGE("out of memory.");
+               ret = DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
        result_cb_info->callback_id = *callback_id;
        result_cb_info->callback = result_callback;
        result_cb_info->user_data = result_cb_user_data;
index fe21968a294e11ca7b1c830565bc11cbc1725145..4c6dee4e00e731ec4d535a991848aae22cacc7d6 100755 (executable)
@@ -397,6 +397,12 @@ static int __init_changed_noti_consumer_list()
 
                consumer_info = (datacontrol_consumer_info *)
                        calloc(1, sizeof(datacontrol_consumer_info));
+               if (consumer_info == NULL) {
+                       _LOGE("out of memory.");
+                       ret = DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+                       break;
+               }
+
                consumer_info->appid = strdup(app_id);
                consumer_info->object_path = strdup(object_path);
                consumer_info->unique_id = strdup(unique_id);
@@ -579,6 +585,11 @@ static int __set_consumer_app_list(
        if (!find_list) {
                consumer_info = (datacontrol_consumer_info *)
                        calloc(1, sizeof(datacontrol_consumer_info));
+               if (consumer_info == NULL) {
+                       _LOGE("out of memory.");
+                       return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               }
+
                consumer_info->appid = strdup(caller);
                consumer_info->object_path = strdup(object_path);
                consumer_info->unique_id = strdup(unique_id);
@@ -2715,6 +2726,10 @@ EXPORT_API int data_control_provider_add_data_change_consumer_filter_cb(
 
        changed_noti_consumer_filter_info_s *filter_info =
                (changed_noti_consumer_filter_info_s *)calloc(1, sizeof(changed_noti_consumer_filter_info_s));
+       if (filter_info == NULL) {
+               _LOGE("out of memory.");
+               return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+       }
 
        *callback_id = __datacontrol_get_data_changed_filter_callback_id();
 
index e753db3ee41a6466e7389636c8c7596a979fb637..956f00b4b5120205515df17d623e8270541f6374 100755 (executable)
@@ -335,6 +335,11 @@ EXPORT_API int data_control_sql_select_with_page(data_control_h provider,
 
        total_arg_count = column_count + DATACONTROL_SELECT_EXTRA_COUNT;
        arg_list = (const char **)malloc(total_arg_count * (sizeof(char *)));
+       if (arg_list == NULL) {
+               _LOGE("out of memory.");
+               bundle_free(b);
+               return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+       }
 
        _LOGI("total arg count %d", total_arg_count);