fix svace issues 85/139185/2 accepted/tizen/4.0/unified/20170816.012727 accepted/tizen/4.0/unified/20170816.015454 accepted/tizen/unified/20170718.174418 submit/tizen/20170718.082643 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0_unified/20170814.115522
authorJongkyu Koo <jk.koo@samsung.com>
Tue, 18 Jul 2017 00:58:07 +0000 (09:58 +0900)
committerJongkyu Koo <jk.koo@samsung.com>
Tue, 18 Jul 2017 05:39:02 +0000 (14:39 +0900)
Change-Id: Ie712ed0c47806f86eb6a74f58217bd9a5b9c5ec7
Signed-off-by: Jongkyu Koo <jk.koo@samsung.com>
common/ctsvc_handle.c
common/ctsvc_vcard.c
server/ctsvc_ipc_server.c
server/ctsvc_ipc_server2.c
server/ctsvc_number_utils.c
server/ctsvc_server.c
server/ctsvc_server_change_subject.c
server/db/ctsvc_db_plugin_phonelog.c
server/db/ctsvc_db_query.c
test/test_query.c
test/test_utils.c

index 7377cfa..2f31d09 100644 (file)
@@ -50,6 +50,12 @@ int ctsvc_handle_clone(contacts_h contact, contacts_h *pcontact)
 
        ctsvc_base_s *base = (ctsvc_base_s*)contact;
        ctsvc_base_s *clone = calloc(1, sizeof(ctsvc_base_s));
+       if (NULL == clone) {
+               /* LCOV_EXCL_START */
+               ERR("calloc() Fail");
+               return CONTACTS_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
+       }
        clone->connection_count = base->connection_count;
        clone->version = base->version;
 
index 2f88a38..2d3490e 100644 (file)
@@ -2677,7 +2677,7 @@ static inline int __ctsvc_vcard_get_name(ctsvc_list_s *name_list, char *val)
 
        contacts_record_set_str(name, _contacts_name.first, NULL);  /* remove FN */
 
-       while (true) {
+       do {
                bool separator = false;
                char *start_temp;
 
@@ -2688,8 +2688,7 @@ static inline int __ctsvc_vcard_get_name(ctsvc_list_s *name_list, char *val)
                CTS_GET_MULTIPLE_COMPONENT(((ctsvc_name_s*)name)->suffix, start, start_temp, separator);
 
                ERR("invalid name type");
-               break;
-       }
+       } while (0);
 
        return CONTACTS_ERROR_NONE;
 }
@@ -3551,7 +3550,7 @@ static inline int __ctsvc_vcard_get_address(ctsvc_list_s *address_list, char *pr
                        text = val;
                }
 
-               while (true) {
+               do {
                        bool separator = false;
 
                        CTS_GET_MULTIPLE_COMPONENT(((ctsvc_address_s*)address)->pobox, text, text_temp, separator);
@@ -3563,8 +3562,7 @@ static inline int __ctsvc_vcard_get_address(ctsvc_list_s *address_list, char *pr
                        CTS_GET_MULTIPLE_COMPONENT(((ctsvc_address_s*)address)->country, text, text_temp, separator);
 
                        ERR("invalid ADR type");
-                       break;
-               }
+               } while (0);
 
                if (((ctsvc_address_s*)address)->pobox || ((ctsvc_address_s*)address)->extended
                                || ((ctsvc_address_s*)address)->street || ((ctsvc_address_s*)address)->locality
index 25b30dd..e57afc8 100644 (file)
@@ -1521,11 +1521,12 @@ void ctsvc_ipc_server_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata,
 
        if (outdata) {
                *outdata = pims_ipc_data_create(0);
-               if (NULL == *outdata)
+               if (NULL == *outdata) {
                        /* LCOV_EXCL_START */
                        ERR("pims_ipc_data_create() Fail");
-               goto DATA_FREE;
-               /* LCOV_EXCL_STOP */
+                       goto DATA_FREE;
+                       /* LCOV_EXCL_STOP */
+               }
 
                if (CONTACTS_ERROR_NONE != ctsvc_ipc_marshal_int(ret, *outdata)) {
                        /* LCOV_EXCL_START */
index c30a40f..72661fa 100644 (file)
@@ -1251,15 +1251,17 @@ void ctsvc_ipc_phone_log_delete(pims_ipc_h ipc, pims_ipc_data_h indata,
                }
                ret = ctsvc_ipc_unmarshal_int(indata, (int*)&op);
                if (ret != CONTACTS_ERROR_NONE) {
+                       /* LCOV_EXCL_START */
                        ERR("ctsvc_ipc_unmarshal_int() Fail");
                        goto ERROR_RETURN;
-                       if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
-                               /* LCOV_EXCL_START */
-                               ret = CONTACTS_ERROR_PERMISSION_DENIED;
-                               goto ERROR_RETURN;
-                               /* LCOV_EXCL_STOP */
-                       }
+                       /* LCOV_EXCL_STOP */
+               }
 
+               if (!ctsvc_have_permission(ipc, CTSVC_PERMISSION_PHONELOG_WRITE)) {
+                       /* LCOV_EXCL_START */
+                       ret = CONTACTS_ERROR_PERMISSION_DENIED;
+                       goto ERROR_RETURN;
+                       /* LCOV_EXCL_STOP */
                }
 
                switch (op) {
index 2a453bc..6958cea 100644 (file)
@@ -899,6 +899,10 @@ static int _numutil_minmatch_number(const char *src, char *dest, int dest_size,
        const char *temp_number;
        const char *cc = ctsvc_get_network_cc(false);
 
+       RETV_IF(NULL == src, CONTACTS_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == dest, CONTACTS_ERROR_INVALID_PARAMETER);
+       RETV_IF(dest_size <= strlen(src), CONTACTS_ERROR_INVALID_PARAMETER);
+
        if ('+' == src[0]) {
                len = _numutil_has_country_code(&src[1], strlen(src)-1);
                temp_number = src + len +1;
@@ -935,8 +939,7 @@ static int _numutil_minmatch_number(const char *src, char *dest, int dest_size,
                        dest[len-i-1] = c;
                }
        } else {
-               memcpy(dest, src, strlen(src));
-               dest[strlen(src)] = 0;
+               memcpy(dest, src, strlen(src)+1);
        }
 
        return CONTACTS_ERROR_NONE;
index 786b799..908ada2 100644 (file)
@@ -264,7 +264,7 @@ static int __server_main(void)
                DBG("%d", ret);
 
                main_loop = g_main_loop_new(NULL, FALSE);
-               pims_ipc_svc_run_main_loop(main_loop);
+               pims_ipc_svc_run_main_loop(&main_loop);
 
                ctsvc_server_final_configuration();
                ctsvc_server_bg_remove_cb();
index de87e8a..58eec84 100644 (file)
@@ -105,6 +105,12 @@ void ctsvc_change_subject_add_changed_phone_log_id(contacts_changed_e type, int
 
        if (NULL == __phone_log_chanaged_info) {
                __phone_log_chanaged_info = calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
+               if (NULL == __phone_log_chanaged_info) {
+                       /* LCOV_EXCL_START */
+                       ERR("calloc() Fail");
+                       return;
+                       /* LCOV_EXCL_STOP */
+               }
                __phone_log_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
                __phone_log_chanaged_info[0] = '\0';
        }
@@ -137,6 +143,12 @@ void ctsvc_change_subject_add_changed_person_id(contacts_changed_e type, int id)
 
        if (NULL == __person_changed_info) {
                __person_changed_info = calloc(CTSVC_SUBSCRIBE_MAX_LEN, sizeof(char));
+               if (NULL == __person_changed_info) {
+                       /* LCOV_EXCL_START */
+                       ERR("calloc() Fail");
+                       return;
+                       /* LCOV_EXCL_STOP */
+               }
                __person_buf_size = CTSVC_SUBSCRIBE_MAX_LEN;
                __person_changed_info[0] = '\0';
        }
index 210397b..0624e5d 100644 (file)
@@ -150,7 +150,6 @@ static int __ctsvc_db_phonelog_update_record(contacts_record_h record)
 
                if (ctsvc_db_change()) {
                        ctsvc_set_phonelog_noti();
-
 #ifdef _CONTACTS_IPC_SERVER
                        ctsvc_change_subject_add_changed_phone_log_id(CONTACTS_CHANGE_UPDATED, phonelog->id);
 #endif
index 60d6806..64960a9 100644 (file)
@@ -707,6 +707,13 @@ static char *_get_search_query_for_data(const char *keyword)
                /* replace '-' -> '_' because FTS does not support search '-' */
                tmp_len = strlen(search_keyword);
                tmp_keyword = calloc(tmp_len + 1, sizeof(char));
+               if (NULL == tmp_keyword) {
+                       /* LCOV_EXCL_START */
+                       ERR("calloc() Fail");
+                       mod_keyword = search_keyword;
+                       break;
+                       /* LCOV_EXCL_STOP */
+               }
                for (i = 0; i < tmp_len; i++)
                        tmp_keyword[i] = ('-' == search_keyword[i]) ? '_' : search_keyword[i];
                tmp_keyword[i] = '\0';
@@ -768,7 +775,7 @@ static inline void __db_create_str_condtion_number(
                ret = ctsvc_normalize_number(clean_num, normal_num, sizeof(normal_num), false);
                normal_num[sizeof(normal_num) -1] = '\0';
                if (0 < ret) {
-                       char min_match[strlen(filter->value.s)+1+5];   /* for cc */
+                       char min_match[sizeof(normal_num)+1];   /* for cc */
                        ret = ctsvc_get_minmatch_number(normal_num, min_match,
                                        sizeof(min_match), ctsvc_get_phonenumber_min_match_digit());
                        if (CONTACTS_ERROR_NONE == ret) {
@@ -1954,6 +1961,8 @@ static int __db_append_search_query(const char *keyword, char **query, int *quer
        if (NULL == search_keyword) {
                /* LCOV_EXCL_START */
                ERR("__ctsvc_db_make_search_keyword() Fail");
+               if (use_replaced_keyword)
+                       free(half_keyword);
                return CONTACTS_ERROR_OUT_OF_MEMORY;
                /* LCOV_EXCL_STOP */
        }
@@ -2119,6 +2128,13 @@ static int __db_append_search_query(const char *keyword, char **query, int *quer
                                /* replace '-' -> '_' because FTS does not support search '-' */
                                tmp_len = strlen(search_keyword);
                                tmp_keyword = calloc(tmp_len + 1, sizeof(char));
+                               if (NULL == tmp_keyword) {
+                                       /* LCOV_EXCL_START */
+                                       ERR("calloc() Fail");
+                                       mod_keyword = search_keyword;
+                                       break;
+                                       /* LCOV_EXCL_STOP */
+                               }
                                for (i = 0; i < tmp_len; i++)
                                        tmp_keyword[i] = ('-' == search_keyword[i]) ? '_' : search_keyword[i];
                                tmp_keyword[i] = '\0';
index c7815f5..ac435d2 100644 (file)
@@ -263,7 +263,7 @@ static int _check_list(const char *uri, contacts_list_h in_list, bool is_snippet
                int contact_id = 0;
                char *display_name = NULL;
                char *number = NULL;
-               int snippet_type = NULL;
+               int snippet_type = 0;
                char *snippet_string = NULL;
 
                switch (uri_type) {
index 8bb30ac..46269fd 100644 (file)
@@ -36,6 +36,10 @@ void test_utils_cleanup(void)
        DBG("count(%d)", count);
 
        int *ids = calloc(count, sizeof(int));
+       if (NULL == ids) {
+               ERR("calloc() Fail");
+               return;
+       }
        int index = 0;
        do {
                contacts_record_h record = NULL;