fixed svace 44/55144/2
authorJeesun Kim <iamjs.kim@samsung.com>
Tue, 22 Dec 2015 08:04:52 +0000 (17:04 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Wed, 23 Dec 2015 06:03:41 +0000 (15:03 +0900)
Change-Id: I2e7e0163d1659d7628258a3b06ba288983a47157

client/cal_client_dbus.c
common/cal_record.c
common/dbus/cal_dbus_helper.c
server/cal_server_account.c
server/cal_server_alarm.c
server/cal_server_dbus.c
server/db/cal_db.c
server/db/cal_db.h
server/db/cal_db_plugin_event.c
server/db/cal_db_rrule.c

index 2c9eff5..f8c3917 100644 (file)
@@ -753,7 +753,6 @@ int cal_dbus_insert_vcalendars(calendar_h handle, const char *stream,
 
        RETV_IF(NULL == handle, CALENDAR_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == stream, CALENDAR_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == out_ids, CALENDAR_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == cal_dbus_object, CALENDAR_ERROR_IPC);
 
index f7ed052..9fe10a9 100644 (file)
@@ -172,7 +172,6 @@ API int calendar_record_create(const char* view_uri, calendar_record_h* out_reco
        RETV_IF(NULL == out_record, CALENDAR_ERROR_INVALID_PARAMETER);
 
        type = cal_view_get_type(view_uri);
-       DBG("----------------------[%s]", view_uri);
        RETV_IF(CAL_RECORD_TYPE_INVALID == type, CALENDAR_ERROR_INVALID_PARAMETER);
 
        cal_record_plugin_cb_s *plugin_cb = cal_record_get_plugin_cb(type);
index b3b9c69..7b68743 100644 (file)
@@ -1144,15 +1144,15 @@ static int _gvariant_to_composite(GVariant * arg_composite_pack, cal_composite_f
        while (g_variant_iter_loop(iter_composite_pack, "(i&siv)",
                                &filter_type, &view_uri, &count_composite, &arg_composite)) {
 
-               cal_composite_filter_s *c = calloc(1, sizeof(cal_composite_filter_s));
-               if (NULL == c) {
+               cal_composite_filter_s *cf = calloc(1, sizeof(cal_composite_filter_s));
+               if (NULL == cf) {
                        ERR("calloc() Fail");
                        break;
                }
-               c->filter_type = CAL_FILTER_COMPOSITE;
-               c->view_uri = cal_strdup(view_uri);
-               c->properties = (cal_property_info_s *)cal_view_get_property_info(view_uri,
-                               &c->property_count);
+               cf->filter_type = CAL_FILTER_COMPOSITE;
+               cf->view_uri = cal_strdup(view_uri);
+               cf->properties = (cal_property_info_s *)cal_view_get_property_info(view_uri,
+                               &cf->property_count);
 
                int is_exit = 0;
                if (0 == count_composite) {
@@ -1171,16 +1171,16 @@ static int _gvariant_to_composite(GVariant * arg_composite_pack, cal_composite_f
                        filter->property_id = property_id;
                        filter->match = match;
                        _gvariant_to_attr_value(composite_filter_type, arg_attr_value, filter);
-                       c->filters = g_slist_append(c->filters, filter);
+                       cf->filters = g_slist_append(cf->filters, filter);
                }
 
                if (1 == is_exit)
                        break;
 
                if (NULL == composite)
-                       composite = c;
+                       composite = cf;
                else
-                       composite->filters = g_slist_append(composite->filters, c);
+                       composite->filters = g_slist_append(composite->filters, cf);
 
        }
        *out_composite = composite;
index 0c146c3..ab23ff5 100644 (file)
@@ -65,10 +65,10 @@ void cal_server_account_deinit(void)
 {
        pthread_mutex_lock(&cal_mutex_account);
 
-       RET_IF(NULL == cal_account_h);
-
-       account_unsubscribe_notification(cal_account_h);
-       cal_account_h = NULL;
+       if (cal_account_h) {
+               account_unsubscribe_notification(cal_account_h);
+               cal_account_h = NULL;
+       }
 
        pthread_mutex_unlock(&cal_mutex_account);
 }
index 8f9a2a7..ba24b4a 100644 (file)
@@ -243,16 +243,18 @@ int cal_server_alarm_get_alert_time(int alarm_id, time_t *tt_alert)
                } else {
                        int y = 0, m = 0, d = 0;
                        int h = 0, n = 0, s = 0;
-                       sscanf(datetime, CAL_FORMAT_LOCAL_DATETIME, &y, &m, &d, &h, &n, &s);
-
-                       st.tm_year = y - 1900;
-                       st.tm_mon = m - 1;
-                       st.tm_mday = d;
-                       st.tm_hour = h;
-                       st.tm_min = n;
-                       st.tm_sec = s;
-                       *tt_alert = mktime(&st);
-                       DBG("datetime[%s] to %02d:%02d:%02d (%d)", datetime, h, n, s, *tt_alert);
+                       if (datetime) {
+                               sscanf(datetime, CAL_FORMAT_LOCAL_DATETIME, &y, &m, &d, &h, &n, &s);
+
+                               st.tm_year = y - 1900;
+                               st.tm_mon = m - 1;
+                               st.tm_mday = d;
+                               st.tm_hour = h;
+                               st.tm_min = n;
+                               st.tm_sec = s;
+                               *tt_alert = mktime(&st);
+                               DBG("datetime[%s] to %02d:%02d:%02d (%d)", datetime, h, n, s, *tt_alert);
+                       }
                }
                sqlite3_finalize(stmt);
                return CALENDAR_ERROR_NONE;
index b8af963..cb66e09 100644 (file)
@@ -296,6 +296,7 @@ static gboolean _handle_replace_records(calDbus *object, GDBusMethodInvocation *
        ret = cal_dbus_utils_gvariant_to_ids(arg_ids, count, &ids);
 
        ret = cal_db_replace_records(list, ids, count);
+       free(ids);
 
        int version = 0;
        version = cal_db_util_get_transaction_ver();
@@ -488,6 +489,7 @@ static gboolean _handle_replace_vcalendars(calDbus *object, GDBusMethodInvocatio
        ret = cal_dbus_utils_gvariant_to_ids(arg_ids, count, &ids);
 
        ret = cal_db_replace_vcalendars(stream, ids, count);
+       free(ids);
 
        int version = 0;
        version = cal_db_util_get_transaction_ver();
index fdd388a..ccb0091 100644 (file)
@@ -51,7 +51,7 @@ extern cal_db_plugin_cb_s cal_db_search_plugin_cb;
 extern cal_db_plugin_cb_s cal_db_timezone_plugin_cb;
 extern cal_db_plugin_cb_s cal_db_extended_plugin_cb;
 
-int cal_db_append_string(char **dst, char *src)
+int cal_db_append_string(char **dst, const char *src)
 {
        RETV_IF(NULL == dst, CALENDAR_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == src, CALENDAR_ERROR_INVALID_PARAMETER);
@@ -69,6 +69,7 @@ int cal_db_append_string(char **dst, char *src)
                }
                return CALENDAR_ERROR_NONE;
        }
+
        int len_dst = strlen(*dst);
        char *tmp = *dst;
        tmp = (char *)realloc(tmp, len_dst + len_src + 2);
@@ -77,8 +78,8 @@ int cal_db_append_string(char **dst, char *src)
                return CALENDAR_ERROR_OUT_OF_MEMORY;
        }
        *dst = tmp;
-       strcat(*dst, " ");
-       strcat(*dst, src);
+       snprintf(*dst + len_dst, len_src + 2, " %s", src);
+
        return CALENDAR_ERROR_NONE;
 }
 
index 01c0cc8..cc52d8c 100644 (file)
@@ -126,7 +126,7 @@ int cal_db_get_current_version(int* current_version);
 int cal_db_get_changes_by_version(const char* view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h* record_list, int *current_calendar_db_version);
 int cal_db_get_changes_exception_by_version(const char* view_uri, int original_event_id, int calendar_db_version, calendar_list_h* record_list);
 
-int cal_db_append_string(char **dst, char *src);
+int cal_db_append_string(char **dst, const char *src);
 cal_db_plugin_cb_s* _cal_db_get_plugin(cal_record_type_e type);
 
 #endif /* __CAL_DB_H__ */
index dda47a0..e196a42 100644 (file)
@@ -312,10 +312,12 @@ static int __get_time_shifted_field(char *old_field, int old_type, int new_type,
 
        int len_t = g_strv_length(t);
 
+       char *field = NULL;
        int len_field = strlen(old_field);
-       char *new = NULL;
-       new = calloc(len_field + (len_t * 8) + 1, sizeof(char)); /* add (len_t * 8) for YYYYMMDD -> YYYYMMDDTHHMMSSZ */
-       if (NULL == new) {
+       len_field += (len_t * 8) + 1;  /* add (len_t * 8) for YYYYMMDD -> YYYYMMDDTHHMMSSZ */
+
+       field = calloc(len_field, sizeof(char)); /* add (len_t * 8) for YYYYMMDD -> YYYYMMDDTHHMMSSZ */
+       if (NULL == field) {
                ERR("calloc() Fail");
                g_strfreev(t);
                return CALENDAR_ERROR_OUT_OF_MEMORY;
@@ -324,6 +326,7 @@ static int __get_time_shifted_field(char *old_field, int old_type, int new_type,
        struct tm tm = {0};
        time_t tt = 0;
 
+       int len = 0;
        int i;
        for (i = 0; i < len_t; i++) {
                int y = 0, m = 0, d = 0;
@@ -402,14 +405,16 @@ static int __get_time_shifted_field(char *old_field, int old_type, int new_type,
                        }
                        break;
                }
-               strcat(new, buf);
+               len += snprintf(field + len, len_field -len, "%s", buf);
+               DBG("[%s]", field);
        }
        g_strfreev(t);
 
        if (new_field)
-               *new_field = new;
+               *new_field = field;
        else
-               free(new);
+               free(field);
+
        return CALENDAR_ERROR_NONE;
 }
 
@@ -2219,13 +2224,15 @@ static int _cal_db_event_update_dirty(calendar_record_h record, int is_dirty_in_
                        if (CALENDAR_ERROR_NONE != ret)
                                continue;
                        if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN) {
-                               ret = _cal_db_event_exdate_insert_normal(event_id, original_exdate, record_exdate, NULL, NULL);
+                               ret = _cal_db_event_exdate_insert_normal(event_id, original_exdate,
+                                               record_exdate, NULL, NULL);
                                WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
 
                        } else {
                                int *exception_ids = NULL;
                                int exception_len = 0;
-                               ret = _cal_db_event_exdate_insert_normal(event_id, original_exdate, record_exdate, &exception_ids, &exception_len);
+                               ret = _cal_db_event_exdate_insert_normal(event_id, original_exdate,
+                                               record_exdate, &exception_ids, &exception_len);
                                WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
                                ret = _cal_db_event_delete_exception(exception_ids, exception_len);
                                WARN_IF(CALENDAR_ERROR_NONE != ret, "_cal_db_event_delete_record() Fail");
@@ -2553,7 +2560,8 @@ static int _cal_db_event_get_deleted_data(int id, int* book_id, int* created_ver
        return CALENDAR_ERROR_NONE;
 }
 
-static int _cal_db_event_exdate_insert_normal(int event_id, const char* original_exdate, const char* exdate, int **exception_ids, int *exception_len)
+static int _cal_db_event_exdate_insert_normal(int event_id, const char* original_exdate,
+               const char* exdate, int **exception_ids, int *exception_len)
 {
        int ret = CALENDAR_ERROR_NONE;
        gchar **patterns1 = NULL;
index 4109665..477ebf0 100644 (file)
@@ -294,14 +294,16 @@ int cal_db_rrule_get_rrule(int id, cal_rrule_s **rrule)
        _rrule->until.time.utime = sqlite3_column_int64(stmt, index++);
 
        temp = sqlite3_column_text(stmt, index++);
-       if (CALENDAR_TIME_LOCALTIME == _rrule->until.type) {
-               sscanf((const char *)temp, CAL_FORMAT_LOCAL_DATETIME,
-                               &_rrule->until.time.date.year,
-                               &_rrule->until.time.date.month,
-                               &_rrule->until.time.date.mday,
-                               &_rrule->until.time.date.hour,
-                               &_rrule->until.time.date.minute,
-                               &_rrule->until.time.date.second);
+       if (temp) {
+               if (CALENDAR_TIME_LOCALTIME == _rrule->until.type) {
+                       sscanf((const char *)temp, CAL_FORMAT_LOCAL_DATETIME,
+                                       &_rrule->until.time.date.year,
+                                       &_rrule->until.time.date.month,
+                                       &_rrule->until.time.date.mday,
+                                       &_rrule->until.time.date.hour,
+                                       &_rrule->until.time.date.minute,
+                                       &_rrule->until.time.date.second);
+               }
        }
 
        _rrule->count = sqlite3_column_int(stmt, index++);