fixed svace issue 12/65412/1 accepted/tizen/common/20160414.142132 accepted/tizen/ivi/20160414.012009 accepted/tizen/mobile/20160414.012045 accepted/tizen/tv/20160414.011947 accepted/tizen/wearable/20160414.011945 submit/tizen/20160413.225258
authorintae, jeon <intae.jeon@samsung.com>
Mon, 11 Apr 2016 00:46:47 +0000 (09:46 +0900)
committerintae, jeon <intae.jeon@samsung.com>
Mon, 11 Apr 2016 00:46:47 +0000 (09:46 +0900)
Change-Id: I746e5ccf6320476bd33608c9a20a0cca5049d80c
Signed-off-by: intae, jeon <intae.jeon@samsung.com>
13 files changed:
email-api/email-api-mail.c
email-common-use/email-convert.c
email-common-use/include/email-debug-log.h
email-core/email-core-account.c
email-core/email-core-gmime.c
email-core/email-core-imap-idle.c
email-core/email-core-imap-mailbox.c
email-core/email-core-mail.c
email-core/email-core-mailbox-sync.c
email-core/email-core-mime.c
email-core/email-core-smtp.c
email-core/email-core-utils.c
email-core/email-storage/email-storage.c

index c80bbc4..b6ea750 100755 (executable)
@@ -279,7 +279,7 @@ EXPORT_API int email_create_db_full()
        for (mailbox_index = 0; mailbox_index < mailbox_count; mailbox_index++) {
                mail_slot_size = mailbox_list[mailbox_index].mail_slot_size;
                for (mail_index = 0; mail_index < mail_slot_size; mail_index++) {
-                       sprintf(mail_table_data.subject, "Subject #%d", mail_index);
+                       snprintf(mail_table_data.subject, 50,"Subject #%d", mail_index);
                        mail_table_data.mailbox_id   = mailbox_list[mailbox_index].mailbox_id;
                        mail_table_data.mailbox_type = mailbox_list[mailbox_index].mailbox_type;
 
index d12ca65..a046f3b 100755 (executable)
@@ -12,7 +12,7 @@
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, 
+* distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
@@ -521,19 +521,19 @@ INTERNAL_FUNC int em_convert_time_t_to_string(time_t *input_time, char **output_
        EM_DEBUG_FUNC_BEGIN("input_time[%p], output_datetime_string[%p]", input_time, output_datetime_string);
        char temp_buffer[20] = { 0, };
        struct tm *temp_time_info;
-
+       struct tm time_buf;
        if (!input_time || !output_datetime_string) {
                EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
                return EMAIL_ERROR_INVALID_PARAM;
        }
 
-       temp_time_info = localtime(input_time);
+       temp_time_info = localtime_r(input_time, &time_buf);
 
        if (!temp_time_info) {
                EM_DEBUG_EXCEPTION("localtime failed.");
                return EMAIL_ERROR_SYSTEM_FAILURE;
        }
-       SNPRINTF(temp_buffer, sizeof(temp_buffer), "%04d%02d%02d%02d%02d%02d", 
+       SNPRINTF(temp_buffer, sizeof(temp_buffer), "%04d%02d%02d%02d%02d%02d",
                temp_time_info->tm_year + 1970, temp_time_info->tm_mon, temp_time_info->tm_mday, temp_time_info->tm_hour, temp_time_info->tm_min, temp_time_info->tm_sec);
 
        *output_datetime_string = EM_SAFE_STRDUP(temp_buffer);
@@ -1291,19 +1291,19 @@ INTERNAL_FUNC char* em_convert_meeting_req_to_byte_stream(email_meeting_request_
                return NULL;
        }
 
-       tn = tpl_map(converted_fmt, 
-                                               &meeting_req->mail_id, 
-                                               &meeting_req->meeting_response, 
-                                               &tb[0], 
-                                               &tb[1], 
-                                               &meeting_req->location, 
-                                               &meeting_req->global_object_id, 
-                                               &meeting_req->time_zone.offset_from_GMT, 
-                                               meeting_req->time_zone.standard_name, 32, 
-                                               &tb[2], 
-                                               &meeting_req->time_zone.standard_bias, 
-                                               meeting_req->time_zone.daylight_name, 32, 
-                                               &tb[3], 
+       tn = tpl_map(converted_fmt,
+                                               &meeting_req->mail_id,
+                                               &meeting_req->meeting_response,
+                                               &tb[0],
+                                               &tb[1],
+                                               &meeting_req->location,
+                                               &meeting_req->global_object_id,
+                                               &meeting_req->time_zone.offset_from_GMT,
+                                               meeting_req->time_zone.standard_name, 32,
+                                               &tb[2],
+                                               &meeting_req->time_zone.standard_bias,
+                                               meeting_req->time_zone.daylight_name, 32,
+                                               &tb[3],
                                                &meeting_req->time_zone.daylight_bias
                                );
        if (!tn) {
@@ -1349,19 +1349,19 @@ INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *stream, int strea
                return;
        }
 
-       tn = tpl_map(converted_fmt, 
-                                               &meeting_req->mail_id, 
-                                               &meeting_req->meeting_response, 
-                                               &tb[0], 
-                                               &tb[1], 
-                                               &meeting_req->location, 
-                                               &meeting_req->global_object_id, 
-                                               &meeting_req->time_zone.offset_from_GMT, 
-                                               meeting_req->time_zone.standard_name, 32, 
-                                               &tb[2], 
-                                               &meeting_req->time_zone.standard_bias, 
-                                               meeting_req->time_zone.daylight_name, 32, 
-                                               &tb[3], 
+       tn = tpl_map(converted_fmt,
+                                               &meeting_req->mail_id,
+                                               &meeting_req->meeting_response,
+                                               &tb[0],
+                                               &tb[1],
+                                               &meeting_req->location,
+                                               &meeting_req->global_object_id,
+                                               &meeting_req->time_zone.offset_from_GMT,
+                                               meeting_req->time_zone.standard_name, 32,
+                                               &tb[2],
+                                               &meeting_req->time_zone.standard_bias,
+                                               meeting_req->time_zone.daylight_name, 32,
+                                               &tb[3],
                                                &meeting_req->time_zone.daylight_bias
                                );
        if (!tn) {
@@ -1387,7 +1387,7 @@ INTERNAL_FUNC void em_convert_byte_stream_to_meeting_req(char *stream, int strea
        EM_DEBUG_FUNC_END();
 }
 
-INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list, 
+INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_t *input_search_filter_list,
                                                                        int input_search_filter_count, int *output_stream_size)
 {
        EM_DEBUG_FUNC_BEGIN("input_search_filter_list [%p] input_search_filter_count [%d]", input_search_filter_list, input_search_filter_count);
@@ -1452,7 +1452,7 @@ INTERNAL_FUNC char* em_convert_search_filter_to_byte_stream(email_search_filter_
        return result_stream;
 }
 
-INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream, 
+INTERNAL_FUNC void em_convert_byte_stream_to_search_filter(char *input_stream,
                                email_search_filter_t **output_search_filter_list, int *output_search_filter_count)
 {
        EM_DEBUG_FUNC_BEGIN("input_stream [%p] output_search_filter_list [%p] output_search_filter_count [%p]", input_stream, output_search_filter_list, output_search_filter_count);
index 1d61c70..ef9141c 100755 (executable)
@@ -281,6 +281,16 @@ extern "C"
                ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
        })
 
+
+#define EM_SAFE_STRNCAT(dest, src, size) \
+       ({\
+               char* _dest = dest;\
+               char* _src = src;\
+               int _size = size;\
+               ((_src) && (_dest))? strncat(_dest, _src, _size) : NULL;\
+       })
+
+
 #define EM_SAFE_STRLEN(s) \
        ({\
                char* _s = (char*)s;\
index c523c12..e21f977 100755 (executable)
@@ -177,14 +177,14 @@ static char *emcore_get_imap_capability_string(MAILSTREAM *input_stream)
 
        if ((imap_capability = imap_cap(input_stream))) {
                if (imap_capability->idle)
-                       EM_SAFE_STRCAT(capability_string, "IDLE ");
+                       EM_SAFE_STRNCAT(capability_string, "IDLE ", sizeof(capability_string) - EM_SAFE_STRLEN(capability_string) - 1);
                if (imap_capability->quota)
-                       EM_SAFE_STRCAT(capability_string, "QUOTA ");
+                       EM_SAFE_STRNCAT(capability_string, "QUOTA ", sizeof(capability_string) - EM_SAFE_STRLEN(capability_string) - 1);
                if (imap_capability->starttls)
-                       EM_SAFE_STRCAT(capability_string, "STARTTLS ");
+                       EM_SAFE_STRNCAT(capability_string, "STARTTLS ", sizeof(capability_string) - EM_SAFE_STRLEN(capability_string) - 1);
 #ifdef __FEATURE_XLIST_SUPPORT__
                if (imap_capability->xlist)
-                       EM_SAFE_STRCAT(capability_string, "XLIST ");
+                       EM_SAFE_STRNCAT(capability_string, "XLIST ", sizeof(capability_string) - EM_SAFE_STRLEN(capability_string) - 1);
 #endif /* __FEATURE_XLIST_SUPPORT__ */
                result_string = EM_SAFE_STRDUP(capability_string);
        }
@@ -317,8 +317,7 @@ INTERNAL_FUNC int emcore_validate_account_with_account_info(char *multi_user_nam
                                err = EMAIL_ERROR_OUT_OF_MEMORY;
                                goto FINISH_OFF;
                        }
-
-                       EM_SAFE_STRCAT(*output_server_capability_string, smtp_capability_string);
+                       EM_SAFE_STRNCAT(*output_server_capability_string,smtp_capability_string , (server_capability_string_length + 1) - EM_SAFE_STRLEN(*output_server_capability_string)- 1);
                        EM_SAFE_STRCAT(*output_server_capability_string, imap_capability_string);
                        EM_DEBUG_LOG("%s", *output_server_capability_string);
                }
index d44a263..4796e4d 100755 (executable)
@@ -49,6 +49,8 @@
 #include "email-debug-log.h"
 #include "email-types.h"
 
+#define SECTIONS_SIZE 16
+
 static int multipart_status = 0;
 
 static void emcore_gmime_pop3_parse_foreach_cb(GMimeObject *parent, GMimeObject *part, gpointer user_data);
@@ -3131,7 +3133,7 @@ INTERNAL_FUNC void emcore_gmime_construct_multipart(GMimeMultipart *multipart,
        part = body->nested.part;
 
        while (part != NULL) {
-               sprintf(id, "%d", i++);
+               snprintf(id, 13, "%d", i++);
 
                if (EM_SAFE_STRLEN(subspec) > 2)
                        section = EM_SAFE_STRDUP(subspec+2);
@@ -3596,7 +3598,7 @@ INTERNAL_FUNC int emcore_gmime_get_body_sections_from_message(GMimeMessage *mess
                                char t[100] = {0,};
                                snprintf(t, sizeof(t), "BODY.PEEK[%s] ", part_path);
                                if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) {
-                                       strcat(sections, t);
+                                       EM_SAFE_STRNCAT(sections, t, sizeof(sections) - EM_SAFE_STRLEN(sections) - 1);
                                } else {
                                        EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes.");
                                        goto FINISH_OFF;
@@ -3608,7 +3610,7 @@ INTERNAL_FUNC int emcore_gmime_get_body_sections_from_message(GMimeMessage *mess
                                        char t[100] = {0,};
                                        snprintf(t, sizeof(t), "BODY.PEEK[%s] ", part_path);
                                        if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) {
-                                               strcat(sections, t);
+                                               EM_SAFE_STRNCAT(sections, t, sizeof(sections)- EM_SAFE_STRLEN(sections) - 1);
                                        } else {
                                                EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes.");
                                                goto FINISH_OFF;
@@ -3703,7 +3705,7 @@ INTERNAL_FUNC int emcore_gmime_get_attachment_section_from_message(GMimeMessage
                                        char t[100] = {0,};
                                        snprintf(t, sizeof(t), "%s", part_path);
                                        if (EM_SAFE_STRLEN(sections) + EM_SAFE_STRLEN(t) < sizeof(sections) - 1) {
-                                               strcat(sections, t);
+                                               EM_SAFE_STRNCAT(sections, t, sizeof(sections) - EM_SAFE_STRLEN(sections) - 1);
                                        } else {
                                                EM_DEBUG_EXCEPTION("Too many body parts. IMAP command may cross 2000bytes.");
                                                goto FINISH_OFF;
@@ -3754,7 +3756,7 @@ static int emcore_gmime_get_section_n_bodysize(char *response, char *section, in
                        s++;
 
                *s = '\0';
-               strcpy(section, p);
+               g_strlcpy(section, p, SECTIONS_SIZE);
 
                /* if (strcmp(section, p)) {
                                        err = EMAIL_ERROR_INVALID_RESPONSE;
@@ -3804,7 +3806,7 @@ INTERNAL_FUNC int emcore_gmime_fetch_imap_body_sections(MAILSTREAM *stream, int
 
        char tag[16] = {0,};
        char command[IMAP_MAX_COMMAND_LENGTH+100] = {0,};
-       char section[16] = {0,};
+       char section[SECTIONS_SIZE] = {0,};
        char *response = NULL;
 
        int server_response_yn = 0;
@@ -4998,8 +5000,8 @@ INTERNAL_FUNC char *emcore_gmime_get_modified_filename_in_duplication(char *sour
 
        gettimeofday(&tv, NULL);
        srand(tv.tv_usec);
-
-       snprintf(temp_filename, MAX_PATH, "%d_%s", rand(), source_filename);
+       unsigned int seed = time(NULL);
+       snprintf(temp_filename, MAX_PATH, "%d_%s", rand_r(&seed), source_filename);
        EM_DEBUG_LOG_SEC("temp_file_name [%s]", temp_filename);
 
        EM_DEBUG_FUNC_END();
index 45fbd3d..50f45a1 100755 (executable)
@@ -335,8 +335,8 @@ static int emcore_connect_and_idle_on_mailbox(char *multi_user_name,
        /* Get Socket ID */
        socket_fd = ((TCPSTREAM *)tcp_stream)->tcpsi;
 
-       sprintf(tag, "%08lx", 0xffffffff & (((MAILSTREAM *)mail_stream)->gensym++));
-       sprintf(cmd, "%s IDLE\015\012", tag);
+       snprintf(tag, sizeof(tag), "%08lx", 0xffffffff & (((MAILSTREAM *)mail_stream)->gensym++));
+       snprintf(cmd, sizeof(cmd), "%s IDLE\015\012", tag);
 
        /* Send IDLE command */
        if (!imap_local->netstream || !net_sout(imap_local->netstream, cmd, (int)EM_SAFE_STRLEN(cmd))) {
index d7c6e95..6585807 100755 (executable)
@@ -715,7 +715,7 @@ int emcore_download_mailbox_list(void *mail_stream,
                        strncpy(reference, stream->original_mailbox, (size_t)EM_SAFE_STRLEN(stream->original_mailbox));
                        if ((s = strchr(reference, '}')))
                                *(++s) = '\0';
-                       strcat(reference, mailbox_name);
+                       EM_SAFE_STRNCAT(reference, mailbox_name, (EM_SAFE_STRLEN(stream->original_mailbox) + strlen(mailbox_name) + 1) - EM_SAFE_STRLEN(reference) - 1);
                }
        } else
                reference = EM_SAFE_STRDUP(stream->original_mailbox);
index 4c1d906..0e922ca 100755 (executable)
@@ -405,12 +405,12 @@ static void emcore_mail_copyuid_ex(MAILSTREAM *stream, char *mailbox, unsigned l
        for (i = 0; i <= index; ++i) {
 
                memset(old_server_uid_char, 0x00, sizeof(old_server_uid_char));
-               sprintf(old_server_uid_char, "%ld", old_server_uid[i]);
+               snprintf(old_server_uid_char, sizeof(old_server_uid_char), "%ld", old_server_uid[i]);
 
                EM_DEBUG_LOG("Old Server Uid Char[%s]", old_server_uid_char);
 
                memset(new_server_uid_char, 0x00, sizeof(new_server_uid_char));
-               sprintf(new_server_uid_char, "%ld", new_server_uid[i]);
+               snprintf(new_server_uid_char, sizeof(new_server_uid_char),"%ld", new_server_uid[i]);
 
                EM_DEBUG_LOG("New Server Uid Char[%s]", new_server_uid_char);
 
@@ -3363,11 +3363,11 @@ void emcore_mail_copyuid(MAILSTREAM *stream, char *mailbox,
        /* search for server _mail_id with value sourceset->first and update it with destset->first */
        /* faizan.h@samsung.com */
        memset(old_server_uid, 0x00, 129);
-       sprintf(old_server_uid, "%ld", sourceset->first);
+       snprintf(old_server_uid, sizeof(old_server_uid), "%ld", sourceset->first);
        EM_DEBUG_LOG(">>>>> old_server_uid = %s", old_server_uid);
 
        memset(g_new_server_uid, 0x00, 129);
-       sprintf(g_new_server_uid, "%ld", destset->first);
+       snprintf(g_new_server_uid, sizeof(g_new_server_uid),"%ld", destset->first);
        EM_DEBUG_LOG(">>>>> new_server_uid =%s", g_new_server_uid);
 
        if (!emstorage_update_server_uid(NULL, 0, old_server_uid, g_new_server_uid, NULL)) {
@@ -3420,7 +3420,7 @@ static int emcore_delete_mails_from_remote_server(char *multi_user_name,
        for (i = 0; i < input_mail_id_count; i++) {
                memset(mail_id_string, 0, sizeof(mail_id_string));
                SNPRINTF(mail_id_string, sizeof(mail_id_string), "%d,", input_mail_ids[i]);
-               strcat(noti_param_string, mail_id_string);
+               EM_SAFE_STRNCAT(noti_param_string, mail_id_string,(sizeof(char) * 10 * input_mail_id_count) - EM_SAFE_STRLEN(noti_param_string) - 1 );
                /* can be optimized by appending sub string with directly pointing on string array kyuho.jo 2011-10-07 */
        }
 
@@ -3853,7 +3853,7 @@ INTERNAL_FUNC int emcore_delete_mails_from_local_storage(char *multi_user_name,
        for (i = 0; i < num; i++) {
                memset(mail_id_string, 0, sizeof(mail_id_string));
                SNPRINTF(mail_id_string, sizeof(mail_id_string), "%d,", mail_ids[i]);
-               strcat(noti_param_string, mail_id_string);
+               EM_SAFE_STRNCAT(noti_param_string, mail_id_string, (sizeof(char) * 10 * num)- EM_SAFE_STRLEN(noti_param_string) -  1);
                /* can be optimized by appending sub string with directly pointing on string array kyuho.jo 2011-10-07 */
        }
 
@@ -5244,7 +5244,7 @@ INTERNAL_FUNC int emcore_move_mail(char *multi_user_name, int mail_ids[], int ma
        for (i = 0; i < mail_ids_count; i++) {
                memset(mail_id_string, 0, 10);
                SNPRINTF(mail_id_string, 10, "%d,", mail_ids[i]);
-               strcat(parameter_string, mail_id_string);
+               EM_SAFE_STRNCAT(parameter_string, mail_id_string, parameter_string_length - EM_SAFE_STRLEN(parameter_string) - 1);
        }
 
        EM_DEBUG_LOG("num : [%d], param string : [%s]", mail_ids_count , parameter_string);
@@ -6334,27 +6334,27 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(char *multi_user_name, int mail_i
                goto FINISH_OFF;
        }
 
-       sprintf(tmp, "%d", msgno);
+       snprintf(tmp, sizeof(tmp),"%d", msgno);
 
        if (mail->flags_seen_field)
-               sprintf(set_flags, "\\Seen");
+               snprintf(set_flags, sizeof(set_flags), "\\Seen");
        else
-               sprintf(clear_flags, "\\Seen");
+               snprintf(clear_flags, sizeof(clear_flags),"\\Seen");
 
        if (mail->flags_answered_field)
-               sprintf(set_flags, "%s \\Answered", set_flags);
+               snprintf(set_flags, sizeof(set_flags),"%s \\Answered", set_flags);
        else
-               sprintf(clear_flags, "%s \\Answered", clear_flags);
+               snprintf(clear_flags, sizeof(clear_flags),"%s \\Answered", clear_flags);
 
        if (mail->flags_flagged_field)
-               sprintf(set_flags, "%s \\Flagged", set_flags);
+               snprintf(set_flags, sizeof(set_flags), "%s \\Flagged", set_flags);
        else
-               sprintf(clear_flags, "%s \\Flagged", clear_flags);
+               snprintf(clear_flags, sizeof(clear_flags),"%s \\Flagged", clear_flags);
 
        if (mail->flags_forwarded_field)
-               sprintf(set_flags, "%s $Forwarded", set_flags);
+               snprintf(set_flags, sizeof(set_flags),"%s $Forwarded", set_flags);
        else
-               sprintf(clear_flags, "%s $Forwarded", clear_flags);
+               snprintf(clear_flags, sizeof(clear_flags),"%s $Forwarded", clear_flags);
 
        if (EM_SAFE_STRLEN(set_flags) > 0) {
                EM_DEBUG_LOG(">>>> Calling mail_setflag [%s] ", set_flags);
@@ -6370,7 +6370,7 @@ INTERNAL_FUNC int emcore_sync_flag_with_server(char *multi_user_name, int mail_i
 
        if (mail->lock_status) {
                memset(set_flags, 0x00, 100);
-               sprintf(set_flags, "Sticky");
+               snprintf(set_flags, sizeof(set_flags), "Sticky");
                if (EM_SAFE_STRLEN(set_flags) > 0) {
                        EM_DEBUG_LOG(">>>> Calling mail_setflag [%s]", set_flags);
                        mail_flag(stream, tmp, set_flags, ST_SET | ST_SILENT);
@@ -6478,15 +6478,15 @@ INTERNAL_FUNC int emcore_sync_seen_flag_with_server(char *multi_user_name, int m
                }
 
                memset(tmp, 0x00, 100);
-               sprintf(tmp, "%d", msgno);
+               snprintf(tmp, sizeof(tmp),"%d", msgno);
 
                memset(set_flags, 0x00, 100);
                memset(clear_flags, 0x00, 100);
 
                if (mail->flags_seen_field)
-                       sprintf(set_flags, "\\Seen");
+                       snprintf(set_flags, sizeof(set_flags),"\\Seen");
                else
-                       sprintf(clear_flags, "\\Seen");
+                       snprintf(clear_flags, sizeof(clear_flags),"\\Seen");
                EM_DEBUG_LOG("new_flag.seen :  %s ", set_flags);
 
                if (EM_SAFE_STRLEN(set_flags) > 0) {
@@ -6967,7 +6967,7 @@ static int emcore_mail_move_by_filter_rule(char *multi_user_name, int account_id
                                SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]);
                        else
                                SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]);
-                       strcat(parameter_string, mail_id_string);
+                       EM_SAFE_STRNCAT(parameter_string, mail_id_string, (sizeof(char) * parameter_string_length) - EM_SAFE_STRLEN(parameter_string) - 1);
                }
 
                EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count);
@@ -7195,7 +7195,7 @@ INTERNAL_FUNC int emcore_update_rule(char *multi_user_name, int filter_id, email
                             SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]);
                     else
                             SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]);
-                    strcat(parameter_string, mail_id_string);
+                    EM_SAFE_STRNCAT(parameter_string, mail_id_string, (sizeof(char) * parameter_string_length) - EM_SAFE_STRLEN(parameter_string) - 1);
             }
 
             EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count);
@@ -7266,7 +7266,7 @@ INTERNAL_FUNC int emcore_delete_rule(char *multi_user_name, int filter_id)
                                SNPRINTF(mail_id_string, 10, "%d", filter_mail_id_list[mail_id_index]);
                        else
                                SNPRINTF(mail_id_string, 10, "%d,", filter_mail_id_list[mail_id_index]);
-                       strcat(parameter_string, mail_id_string);
+                       EM_SAFE_STRNCAT(parameter_string, mail_id_string,( sizeof(char) * parameter_string_length) - EM_SAFE_STRLEN(parameter_string) - 1 );
                }
 
                EM_DEBUG_LOG("filtered_mail_id_count [%d]", filter_mail_id_count);
@@ -8107,6 +8107,7 @@ int emcore_search_mail_and_uids(MAILSTREAM *stream, email_search_filter_t *input
        int  uid_count = 0;
        char          *search_filter_string = NULL;
        char          *uid_range_string = NULL;
+       char *ptr = NULL;
        emcore_uid_list *uid_list_for_listing = NULL;
 
        if (stream  == NULL || output_uid_list == NULL || input_search_filter == NULL || output_uid_count == NULL) {
@@ -8171,7 +8172,7 @@ int emcore_search_mail_and_uids(MAILSTREAM *stream, email_search_filter_t *input
                if ((p = strstr(response, " SEARCH "))) {
                        *p = '\0'; p  += strlen(" SEARCH ");
 
-                       result = strtok(p, delims);
+                       result = strtok_r(p, delims, &ptr);
 
                        while (result  != NULL) {
                                EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result);
@@ -8187,7 +8188,7 @@ int emcore_search_mail_and_uids(MAILSTREAM *stream, email_search_filter_t *input
                                if (uid_list_for_listing != NULL)
                                        uid_elem->next = uid_list_for_listing;
                                uid_list_for_listing = uid_elem;
-                               result = strtok(NULL, delims);
+                               result = strtok_r(NULL, delims, &ptr);
                                uid_count++;
                        }
 
index 604655c..859b2b0 100755 (executable)
@@ -559,6 +559,7 @@ int emcore_get_uids_order_by_datetime_from_imap_server(MAILSTREAM *stream, int c
        char before_date_string[20] = {0};
        char *since_date_string = NULL;
        char *uid_range_string = NULL;
+       char *ptr = NULL;
        emcore_uid_list *uid_list_for_listing = NULL;
 
        if (!stream || !output_uid_list) {
@@ -633,7 +634,7 @@ int emcore_get_uids_order_by_datetime_from_imap_server(MAILSTREAM *stream, int c
                        if ((p = strstr(response, " SEARCH "))) {
                                *p = '\0'; p  += strlen(" SEARCH ");
 
-                               result = strtok(p, delims);
+                               result = strtok_r(p, delims, &ptr);
 
                                while (result  != NULL) {
                                        EM_DEBUG_LOG_DEV("UID VALUE DEEP is [%s]", result);
@@ -649,7 +650,7 @@ int emcore_get_uids_order_by_datetime_from_imap_server(MAILSTREAM *stream, int c
                                        if (uid_list_for_listing != NULL)
                                                uid_elem->next = uid_list_for_listing;
                                        uid_list_for_listing = uid_elem;
-                                       result = strtok(NULL, delims);
+                                       result = strtok_r(NULL, delims, &ptr);
                                        uid_count++;
                                }
 
@@ -716,6 +717,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui
        time_t         week_before_RawTime = 0;
        char  date_string[16];
        char *mon = NULL;
+       char *ptr = NULL;
 
        if (!stream || !uid_list) {
                EM_DEBUG_EXCEPTION(" stream[%p], uid_list[%p]", stream, uid_list);
@@ -747,7 +749,8 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui
        week_before_RawTime = RawTime - 604800;
 
        /* Reading the current timeinfo */
-       timeinfo = localtime(&week_before_RawTime);
+       struct tm tm_buf;
+       timeinfo = localtime_r(&week_before_RawTime, &tm_buf);
        if (timeinfo == NULL) {
                EM_DEBUG_EXCEPTION("localtime failed");
                err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -811,7 +814,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui
                if ((p = strstr(response, " SEARCH "))) {
                    *p = '\0'; p  += strlen(" SEARCH ");
 
-                   result = strtok(p, delims);
+                   result = strtok_r(p, delims, &ptr);
 
                    while (result  != NULL) {
                                EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result);
@@ -827,7 +830,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui
                                if (*uid_list  != NULL)
                                        uid_elem->next = *uid_list;
                                *uid_list = uid_elem;
-                               result = strtok(NULL, delims);
+                               result = strtok_r(NULL, delims, &ptr);
                    }
 
                        EM_SAFE_FREE(response);
@@ -3383,7 +3386,7 @@ void mail_appenduid(char *mailbox, unsigned long uidvalidity, SEARCHSET *set)
 
     memset(g_append_uid_rsp, 0x00, 129);
 
-    sprintf(g_append_uid_rsp, "%ld", set->first);
+    snprintf(g_append_uid_rsp, sizeof(g_append_uid_rsp), "%ld", set->first);
     EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp);
 }
 
@@ -3510,7 +3513,7 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name,
        snprintf(message_size, sizeof(message_size), "%d", len);
        INIT(&str, mail_string, message_size, EM_SAFE_STRLEN(message_size));
 
-       sprintf(set_flags, "\\Seen");
+       snprintf(set_flags, sizeof(set_flags), "\\Seen");
 
        int total_size = len;
        int data_size = 0;
index 75caa99..013b8f8 100755 (executable)
@@ -305,8 +305,8 @@ char *emcore_mime_get_save_file_name(int *err_code)
        srand(tv.tv_usec);
 
        memset(tempname, 0x00, sizeof(tempname));
-
-       SNPRINTF(tempname, sizeof(tempname), "%s%s%d", MAILTEMP, DIR_SEPERATOR, rand());
+       unsigned int seed = time(NULL);
+       SNPRINTF(tempname, sizeof(tempname), "%s%s%d", MAILTEMP, DIR_SEPERATOR, rand_r(&seed));
        EM_DEBUG_FUNC_END();
        return EM_SAFE_STRDUP(tempname);
 }
@@ -1158,7 +1158,8 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg,
        /* Create rand mail id of eml */
        gettimeofday(&tv, NULL);
        srand(tv.tv_usec);
-       eml_mail_id = rand();
+       unsigned int seed = time(NULL);
+       eml_mail_id = rand_r(&seed);
 
        p_mail_data = (email_mail_data_t *)em_malloc(sizeof(email_mail_data_t));
        if (p_mail_data == NULL) {
@@ -1215,7 +1216,7 @@ INTERNAL_FUNC int emcore_make_mail_data_from_mime_data(struct _m_mesg *mmsg,
                if (cnt_info->text.html_charset != NULL) {
                        SNPRINTF(html_body, MAX_PATH, "%s%s", cnt_info->text.html_charset, HTML_EXTENSION_STRING);
                } else {
-                       strcpy(html_body, UNKNOWN_CHARSET_HTML_TEXT_FILE);
+                       g_strlcpy(html_body, UNKNOWN_CHARSET_HTML_TEXT_FILE, MAX_PATH);
                }
 
                if (!emstorage_get_save_name(multi_user_name, EML_FOLDER, eml_mail_id,
index 8c5093a..324b8e5 100755 (executable)
@@ -2872,7 +2872,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err)
 
        int cid_length = RANDOM_NUMBER_LENGTH + EM_SAFE_STRLEN(hostname) + 2, random_number_1, random_number_2, random_number_3, random_number_4;
        char *cid_string = NULL;
-
+       unsigned int seed = time(NULL);
        cid_string = malloc(cid_length);
 
        if (!cid_string) {
@@ -2883,11 +2883,11 @@ char *emcore_generate_content_id_string(const char *hostname, int *err)
 
        memset(cid_string, 0, cid_length);
 
-       srand(time(NULL) + rand());
-       random_number_1 = rand() * rand();
-       random_number_2 = rand() * rand();
-       random_number_3 = rand() * rand();
-       random_number_4 = rand() * rand();
+       srand(time(NULL) + rand_r(&seed));
+       random_number_1 = rand_r(&seed) * rand_r(&seed);
+       random_number_2 = rand_r(&seed) * rand_r(&seed);
+       random_number_3 = rand_r(&seed) * rand_r(&seed);
+       random_number_4 = rand_r(&seed) * rand_r(&seed);
 
        SNPRINTF(cid_string, cid_length, "<%08x%08x%08x%08x@%s>", random_number_1, random_number_2, random_number_3, random_number_4, hostname);
 
@@ -3611,7 +3611,8 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_
        if (!is_incomplete) {
                char  localtime_string[DATE_STR_LENGTH] = { 0, };
                time_t tn     = time(0);
-               struct tm *t  = gmtime(&tn);
+               struct tm time_buf;
+               struct tm *t  = gmtime_r(&tn, &time_buf);
                if (t == NULL) {
                        EM_DEBUG_EXCEPTION("gmtime failed");
                        error = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -3688,43 +3689,43 @@ static char *emcore_get_digest_string(int digest_type, int mime_type)
        case EMAIL_PGP_ENCRYPTED:
        case EMAIL_PGP_SIGNED_AND_ENCRYPTED:
                memset(p_digest_string, 0x00, sizeof(p_digest_string));
-               strcpy(p_digest_string, "pgp-");
+               g_strlcpy(p_digest_string, "pgp-", sizeof(p_digest_string));
                break;
        }
 
        switch (digest_type) {
        case DIGEST_TYPE_SHA1:
-               strcat(p_digest_string, "sha1");
+               strncat(p_digest_string, "sha1", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_MD5:
-               strcat(p_digest_string, "md5");
+               strncat(p_digest_string, "md5", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_RIPEMD160:
-               strcat(p_digest_string, "ripemd160");
+               strncat(p_digest_string, "ripemd160", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_MD2:
-               strcat(p_digest_string, "md2");
+               strncat(p_digest_string, "md2", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_TIGER192:
-               strcat(p_digest_string, "tiger192");
+               strncat(p_digest_string, "tiger192", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_HAVAL5160:
-               strcat(p_digest_string, "haval5160");
+               strncat(p_digest_string, "haval5160", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_SHA256:
-               strcat(p_digest_string, "sha256");
+               strncat(p_digest_string, "sha256", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_SHA384:
-               strcat(p_digest_string, "sha384");
+               strncat(p_digest_string, "sha384", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_SHA512:
-               strcat(p_digest_string, "sha512");
+               strncat(p_digest_string, "sha512", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_SHA224:
-               strcat(p_digest_string, "sha224");
+               strncat(p_digest_string, "sha224", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        case DIGEST_TYPE_MD4:
-               strcat(p_digest_string, "md4");
+               strncat(p_digest_string, "md4", sizeof(p_digest_string) - EM_SAFE_STRLEN(p_digest_string) - 1);
                break;
        }
 
index 75d400a..7c0af9c 100755 (executable)
@@ -480,7 +480,6 @@ int emcore_get_temp_file_name(char **filename, int *err_code)
 
        int ret = false;
        int error = EMAIL_ERROR_NONE;
-
        if (filename == NULL) {
                EM_DEBUG_EXCEPTION("\t filename[%p]\n", filename);
                error = EMAIL_ERROR_INVALID_PARAM;
@@ -1724,7 +1723,7 @@ INTERNAL_FUNC int emcore_add_notification_for_send(char *multi_user_name, int ac
                textdomain("sys_string");
 */
                setlocale(LC_MESSAGES, vconf_get_str(VCONFKEY_LANGSET));
-               bindtextdomain(NATIVE_EMAIL_DOMAIN, tzplatform_mkpath(TZ_SYS_RO_APP,"org.tizen.email/res/localea"));
+               bindtextdomain(NATIVE_EMAIL_DOMAIN, tzplatform_mkpath(TZ_SYS_RO_APP,"org.tizen.email/res/locale"));
                textdomain(NATIVE_EMAIL_DOMAIN);
 
                switch (sending_error) {
@@ -3762,8 +3761,8 @@ int emcore_make_attachment_file_name_with_extension(char *source_file_name, char
                 goto FINISH_OFF;
             }
 
-                       strcat(attachment_file_name, ".");
-                       strcat(attachment_file_name, sub_type);
+                       EM_SAFE_STRNCAT(attachment_file_name, ".", MAX_PATH - EM_SAFE_STRLEN(attachment_file_name) - 1);
+                       EM_SAFE_STRNCAT(attachment_file_name, sub_type, MAX_PATH - EM_SAFE_STRLEN(attachment_file_name) - 1);
                        EM_DEBUG_LOG_SEC("attachment_file_name with extension[%s] ", attachment_file_name);
                } else
                        EM_DEBUG_LOG("UnKnown Extesnsion");
@@ -3946,7 +3945,7 @@ INTERNAL_FUNC int emcore_search_string_from_file(char *file_path, char *search_s
                                goto FINISH_OFF;
                        }
 
-                       sprintf(cid_string, "cid:%s", search_string);
+                       snprintf(cid_string, EM_SAFE_STRLEN(search_string) + EM_SAFE_STRLEN("cid:") + 1, "cid:%s", search_string);
 
                        modified_string = em_replace_string(stripped, cid_string, new_string);
                        if (modified_string) {
index 22bddf1..be1f3d5 100755 (executable)
@@ -1347,7 +1347,7 @@ static int _get_stmt_field_data_string_without_allocation(DB_STMT hStmt, char *b
                memset(buf, 0, buffer_size);
                strncpy(buf, (char *)sqlite3_column_text(hStmt, index), buffer_size - 1);
        } else
-               strcpy(buf, "");
+               g_strlcpy(buf, "", buffer_size);
 
 #ifdef _PRINT_STORAGE_LOG_
        EM_DEBUG_LOG("buf[%s], index[%d]", buf, index);
@@ -11621,7 +11621,7 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id,
                                goto FINISH_OFF;
                        }
 
-                       sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, modified_name);
+                       snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_name);
                        EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name);
                        EM_SAFE_FREE(modified_name);
                } else {
@@ -11634,11 +11634,11 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id,
                                        goto FINISH_OFF;
                                }
 
-                               sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, modified_name);
+                               snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_name);
                                EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name);
                                EM_SAFE_FREE(modified_name);
                        } else {
-                               sprintf(path_buf+EM_SAFE_STRLEN(path_buf), "%s%s", DIR_SEPERATOR, modified_fname);
+                               snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_fname);
                        }
                }
        }
@@ -11651,10 +11651,10 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id,
                        EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
                        goto FINISH_OFF;
                }
-        sprintf(move_buf, "%s/%s", prefix_path, path_buf);
+        snprintf(move_buf, 512, "%s/%s", prefix_path, path_buf);
         EM_DEBUG_LOG("move_buf : [%s]", move_buf);
     } else {
-        sprintf(move_buf, "%s", path_buf);
+        snprintf(move_buf, 512, "%s", path_buf);
         EM_DEBUG_LOG("move_buf : [%s]", move_buf);
     }
 
@@ -11968,8 +11968,8 @@ static int _get_temp_file_name(char **filename, int *err_code)
 
        gettimeofday(&tv, NULL);
        srand(tv.tv_usec);
-
-       SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, '/', rand());
+       unsigned int seed = time(NULL);
+       SNPRINTF(tempname, sizeof(tempname), "%s%c%d", MAILTEMP, '/', rand_r(&seed));
 
        char *p = EM_SAFE_STRDUP(tempname);
        if (p == NULL) {
@@ -16444,7 +16444,7 @@ INTERNAL_FUNC int emstorage_write_conditional_clause_for_getting_mail_list(char
 
        if (input_filter_count > 0) {
                query_size = QUERY_SIZE;
-               strcpy(conditional_clause_string, " WHERE ");
+               g_strlcpy(conditional_clause_string, " WHERE ", QUERY_SIZE);
 
                for (i = 0; i < input_filter_count; i++) {
                        switch (input_filter_list[i].list_filter_item_type) {