From: kamaljeet Date: Sat, 16 Feb 2019 13:26:14 +0000 (+0530) Subject: coverity issue email-service X-Git-Tag: accepted/tizen/unified/20190218.064034^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c131a7261ca9d181a0045935bcb39cc79a46fde;p=platform%2Fcore%2Fmessaging%2Femail-service.git coverity issue email-service Change-Id: Id1a22f72e23f942306206650a09e7806a55a65a5 Signed-off-by: kamaljeet --- diff --git a/email-core/email-core-account.c b/email-core/email-core-account.c index 711d166..3432446 100755 --- a/email-core/email-core-account.c +++ b/email-core/email-core-account.c @@ -509,7 +509,8 @@ INTERNAL_FUNC int emcore_delete_account(char *multi_user_name, int account_id, i #ifdef __FEATURE_KEEP_CONNECTION__ /* emcore_reset_streams(); */ - emcore_remove_connection_info(account_id); + if (emcore_remove_connection_info(account_id) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_remove_connection_info failed \n"); #endif if ((err = emcore_delete_all_mails_of_acount(multi_user_name, account_id)) != EMAIL_ERROR_NONE) { @@ -532,7 +533,8 @@ INTERNAL_FUNC int emcore_delete_account(char *multi_user_name, int account_id, i } emcore_display_unread_in_badge(multi_user_name); - emcore_delete_notification_by_account(multi_user_name, account_id, true, true, true); + if (emcore_delete_notification_by_account(multi_user_name, account_id, true, true, true) != EMAIL_ERROR_NONE) + EM_DEBUG_EXCEPTION("emcore_delete_notification_by_account failed \n"); ret = true; diff --git a/email-core/email-core-dpm.c b/email-core/email-core-dpm.c index 27f2760..ad9684d 100644 --- a/email-core/email-core-dpm.c +++ b/email-core/email-core-dpm.c @@ -1,86 +1,87 @@ -#include "email-core-mail.h" -#include "email-internal-types.h" -#include "email-types.h" -#include "email-debug-log.h" -#include "email-core-dpm.h" - -static int g_dpm_policy_status = 0; - - -#include - - -void on_restriction(const char* policy, const char* value, void* user_data) -{ - int is_allowed = strcmp(value, "allowed") == 0 ? 1 : 0; - /* true = 1; - false = 0; */ - - EM_DEBUG_LOG("dpm_cb_status : %d", is_allowed); - g_dpm_policy_status = is_allowed; -} - -static int callback_id; -static device_policy_manager_h dpm; - -void emcore_dpm_instance_create() -{ - - - #ifdef TIZEN_FEATURE_EMAIL_DPM - - EM_DEBUG_LOG("dpm_instance_create"); - dpm = dpm_manager_create(); - int allowed; - void *user_data = NULL; - int ret = dpm_restriction_get_popimap_email_state(dpm, &allowed); - if (ret != DPM_ERROR_NONE) { - EM_DEBUG_LOG("dpm_error : %d", ret); - //TODO add error routin - } - - EM_DEBUG_LOG("dpm_policy : %d", allowed); - if (allowed == false) { - - /* OPERATION IS RESTRICTED */ - g_dpm_policy_status = false; - - } else if (allowed == true) { - - /* OPERATION IS ALLOWED */ - g_dpm_policy_status = true; - - } else { - EM_DEBUG_LOG("dpm wrong status : %d", allowed); - - //TODO add error routin - } - - // Callback will be called when policy is changed - dpm_add_policy_changed_cb(dpm , "popimap_email", on_restriction, user_data, &callback_id); - - #else - - EM_DEBUG_LOG("dpm_off"); - - #endif /* TIZEN_FEATURE_EMAIL_DPM */ - -} -int emcore_get_dpm_status() -{ - - EM_DEBUG_LOG("get_dpm_status()"); - #ifdef TIZEN_FEATURE_EMAIL_DPM - return g_dpm_policy_status; - #else - return true; - #endif /* TIZEN_FEATURE_EMAIL_DPM */ - -} - -void dpm_interface_destroy() -{ - dpm_remove_policy_changed_cb(dpm, callback_id); - dpm_manager_destroy(dpm); -} - +#include "email-core-mail.h" +#include "email-internal-types.h" +#include "email-types.h" +#include "email-debug-log.h" +#include "email-core-dpm.h" + +static int g_dpm_policy_status = 0; + + +#include + + +void on_restriction(const char* policy, const char* value, void* user_data) +{ + int is_allowed = strcmp(value, "allowed") == 0 ? 1 : 0; + /* true = 1; + false = 0; */ + + EM_DEBUG_LOG("dpm_cb_status : %d", is_allowed); + g_dpm_policy_status = is_allowed; +} + +static int callback_id; +static device_policy_manager_h dpm; + +void emcore_dpm_instance_create() +{ + + + #ifdef TIZEN_FEATURE_EMAIL_DPM + + EM_DEBUG_LOG("dpm_instance_create"); + dpm = dpm_manager_create(); + int allowed; + void *user_data = NULL; + int ret = dpm_restriction_get_popimap_email_state(dpm, &allowed); + if (ret != DPM_ERROR_NONE) { + EM_DEBUG_LOG("dpm_error : %d", ret); + //TODO add error routin + } + + EM_DEBUG_LOG("dpm_policy : %d", allowed); + if (allowed == false) { + + /* OPERATION IS RESTRICTED */ + g_dpm_policy_status = false; + + } else if (allowed == true) { + + /* OPERATION IS ALLOWED */ + g_dpm_policy_status = true; + + } else { + EM_DEBUG_LOG("dpm wrong status : %d", allowed); + + //TODO add error routin + } + + // Callback will be called when policy is changed + if (dpm_add_policy_changed_cb(dpm , "popimap_email", on_restriction, user_data, &callback_id) != 0) + EM_DEBUG_LOG("dpm_add_policy_changed_cb failed /n"); + + #else + + EM_DEBUG_LOG("dpm_off"); + + #endif /* TIZEN_FEATURE_EMAIL_DPM */ + +} +int emcore_get_dpm_status() +{ + + EM_DEBUG_LOG("get_dpm_status()"); + #ifdef TIZEN_FEATURE_EMAIL_DPM + return g_dpm_policy_status; + #else + return true; + #endif /* TIZEN_FEATURE_EMAIL_DPM */ + +} + +void dpm_interface_destroy() +{ + dpm_remove_policy_changed_cb(dpm, callback_id); + dpm_manager_destroy(dpm); +} + diff --git a/email-core/email-core-gmime.c b/email-core/email-core-gmime.c index caa8b60..9c331a6 100755 --- a/email-core/email-core-gmime.c +++ b/email-core/email-core-gmime.c @@ -4300,7 +4300,10 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int if (disposition_header) g_object_unref(disposition_header); } - if (buf) g_remove(buf); + if (buf) { + if (g_remove(buf) != 0) + EM_DEBUG_LOG_DEV("Fail to Remove buffer \n"); + } EM_SAFE_FREE(buf); } else if ((tag_position = g_strrstr(response, tag))) /* end of response */ { if (!strncmp(tag_position + EM_SAFE_STRLEN(tag) + 1, "OK", 2)) { diff --git a/email-core/email-core-mail.c b/email-core/email-core-mail.c index 1e67e69..9b00f85 100755 --- a/email-core/email-core-mail.c +++ b/email-core/email-core-mail.c @@ -2271,10 +2271,12 @@ FINISH_OFF: if (!auto_download) { if (ret == TRUE) - emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0); + if (emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FINISH, mail_id, NULL, nth, 0) != 1) + EM_DEBUG_LOG(">>>>>>emcore_notify_network_event failed \n "); else { if (err != EMAIL_ERROR_CANCELLED) - emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err); + if (emcore_notify_network_event(NOTI_DOWNLOAD_ATTACH_FAIL, mail_id, NULL, nth, err) != 1) + EM_DEBUG_LOG(">>>>>>emcore_notify_network_event failed \n "); } } @@ -3335,9 +3337,11 @@ FINISH_OFF: if (!auto_download) { if (ret == TRUE) - emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0); + if (emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FINISH, mail_id, NULL, event_handle, 0) != 0) + EM_DEBUG_LOG(">>>>> emcore_notify_network_event failed \n "); else - emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err); + if (emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, event_handle, err) != 0) + EM_DEBUG_LOG(">>>>> emcore_notify_network_event failed \n "); } if (err_code != NULL) diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index 321ba17..97d86be 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -425,8 +425,10 @@ FINISH_OFF: /* prevent 34226 */ EM_SAFE_FREE(body->sparep); EM_SAFE_CLOSE(fd); /*prevent 34498*/ EM_SAFE_FREE(p); - if (tmp_file_path) - g_remove(tmp_file_path); + if (tmp_file_path) { + if (g_remove(tmp_file_path) != 0) + EM_DEBUG_EXCEPTION(" Fail to remove tmp_file_path \n"); + } EM_SAFE_FREE(tmp_file_path); if (fp_html) fclose(fp_html); @@ -673,7 +675,8 @@ FINISH_OFF: if (!file_exist) *data = EM_SAFE_STRDUP(fname); } else if (fname != NULL) { - remove(fname); + if (remove(fname) != 0) + EM_DEBUG_EXCEPTION("Fail to remove fname \n"); } EM_SAFE_FREE(fname); diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index 12c0914..90a9928 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -1609,10 +1609,14 @@ static void *_emstorage_open_once(char *multi_user_name, int *err_code) _delete_temp_file(buf); EM_SAFE_FREE(prefix_path); } else { - mkdir(DATA_PATH, DIRECTORY_PERMISSION); - mkdir(EMAIL_PATH, DIRECTORY_PERMISSION); - mkdir(MAIL_HOME, DIRECTORY_PERMISSION); - mkdir(MAIL_TEMP, DIRECTORY_PERMISSION); + if (mkdir(DATA_PATH, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(EMAIL_PATH, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(MAIL_HOME, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(MAIL_TEMP, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); _delete_temp_file(MAIL_TEMP); } @@ -1838,9 +1842,12 @@ INTERNAL_FUNC int emstorage_init_db(char *multi_user_name) email_uid = UID_DEFAULT; - chmod(EMAIL_SERVICE_DB_FILE_PATH, 0660); - chmod(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, 0660); - chmod(EMAIL_SQL_PATH, 0660); + if (chmod(EMAIL_SERVICE_DB_FILE_PATH, 0660) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); + if (chmod(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, 0660) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); + if (chmod(EMAIL_SQL_PATH, 0660) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); ret = chown(EMAIL_SERVICE_DB_FILE_PATH, email_uid, email_gid); if (0 != ret) @@ -11522,9 +11529,12 @@ INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transacti goto FINISH_OFF; } - mkdir(MAIL_HOME, DIRECTORY_PERMISSION); - mkdir(MAIL_TEMP, DIRECTORY_PERMISSION); - chmod(MAIL_TEMP, 0777); + if (mkdir(MAIL_HOME, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(MAIL_TEMP, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (chmod(MAIL_TEMP, 0777) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); /* first clear index. */ while (indexes->object_name) { @@ -11860,7 +11870,8 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in } if (account_id == EML_FOLDER) - chmod(buf, 0777); + if (chmod(buf, 0777) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); } } @@ -11978,11 +11989,16 @@ INTERNAL_FUNC void emstorage_create_dir_if_delete() { EM_DEBUG_FUNC_BEGIN(); - mkdir(DATA_PATH, DIRECTORY_PERMISSION); - mkdir(EMAIL_PATH, DIRECTORY_PERMISSION); - mkdir(MAIL_HOME, DIRECTORY_PERMISSION); - mkdir(MAIL_TEMP, DIRECTORY_PERMISSION); - chmod(MAIL_TEMP, 0777); + if (mkdir(DATA_PATH, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(EMAIL_PATH, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(MAIL_HOME, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (mkdir(MAIL_TEMP, DIRECTORY_PERMISSION) != 0) + EM_DEBUG_EXCEPTION("Fail to create the directory \n"); + if (chmod(MAIL_TEMP, 0777) != 0) + EM_DEBUG_EXCEPTION("Fail to change the permission \n"); EM_DEBUG_FUNC_END(); } diff --git a/email-daemon/email-daemon-event.c b/email-daemon/email-daemon-event.c index e8b190d..a7d9e70 100644 --- a/email-daemon/email-daemon-event.c +++ b/email-daemon/email-daemon-event.c @@ -1369,8 +1369,8 @@ static int event_handler_EMAIL_EVENT_DOWNLOAD_BODY(char *multi_user_name, int ac if (mail) emstorage_free_mail(&mail, 1, NULL); - emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err); - + if (emcore_notify_network_event(NOTI_DOWNLOAD_BODY_FAIL, mail_id, NULL, handle_to_be_published, err) != 0) + EM_DEBUG_EXCEPTION(">>>>> emcore_notify_network_event failed \n "); goto FINISH_OFF; } @@ -1447,7 +1447,8 @@ static int event_handler_EMAIL_EVENT_SYNC_FLAGS_FIELD_TO_SERVER(char *multi_user /* So in event update again the DB field */ if (err != EMAIL_ERROR_NONE) { /* If the emcore_sync_flags_field_with_server is failed, rollback the db */ - emcore_set_flags_field(multi_user_name, account_id, mail_ids, num, field_type, value ? 0 : 1, NULL); + if (emcore_set_flags_field(multi_user_name, account_id, mail_ids, num, field_type, value ? 0 : 1, NULL) != 0) + EM_DEBUG_EXCEPTION("emcore_set_flags_field failed \n"); } if (error) *error = err; diff --git a/test/testapp-mail.c b/test/testapp-mail.c index 9d4002f..094e326 100644 --- a/test/testapp-mail.c +++ b/test/testapp-mail.c @@ -226,7 +226,8 @@ static gboolean testapp_test_add_mail(int *result_mail_id) if (0 >= scanf("%d", &mailbox_id)) testapp_print("Invalid input. "); - email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data); + if (email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox_data) != EMAIL_ERROR_NONE) + testapp_print("email_get_mailbox_by_mailbox_id failed "); test_mail_data = malloc(sizeof(email_mail_data_t)); memset(test_mail_data, 0x00, sizeof(email_mail_data_t)); @@ -368,7 +369,8 @@ static gboolean testapp_test_update_mail() if (0 >= scanf("%d", &mail_id)) testapp_print("Invalid input. "); - email_get_mail_data(mail_id, &test_mail_data); + if (email_get_mail_data(mail_id, &test_mail_data) != EMAIL_ERROR_NONE) + testapp_print("email_get_mail_data Failed \n "); if (!test_mail_data) { testapp_print("email_get_mail_data() failed\n"); @@ -543,7 +545,8 @@ static gboolean testapp_test_mail_send(int *result_mail_id) testapp_add_mail_for_sending(&added_mail_id); if (added_mail_id) { - email_get_mail_data(added_mail_id, &result_mail_data); + if (email_get_mail_data(added_mail_id, &result_mail_data) != EMAIL_ERROR_NONE) + testapp_print("email_get_mail_data Failed \n "); testapp_print("Calling email_send_mail...\n");