From: Richard Russon Date: Wed, 5 Apr 2017 13:42:50 +0000 (+0100) Subject: coverity: strfcpy X-Git-Tag: neomutt-20170414~10^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=785959e10e72260a75e01245f5455ab0222b62e4;p=neomutt coverity: strfcpy Replace strncpy with strfcpy to avoid unterminated strings. --- diff --git a/headers.c b/headers.c index 5f2b6f315..cb651816e 100644 --- a/headers.c +++ b/headers.c @@ -281,7 +281,7 @@ int mutt_label_message(HEADER *hdr) *buf = '\0'; if (hdr != NULL && hdr->env->x_label != NULL) { - strncpy(buf, hdr->env->x_label, LONG_STRING); + strfcpy(buf, hdr->env->x_label, sizeof(buf)); } if (mutt_get_field("Label: ", buf, sizeof(buf), MUTT_LABEL /* | MUTT_CLEAR */) != 0) diff --git a/imap/auth_gss.c b/imap/auth_gss.c index 8f96c9fd4..508788736 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -56,7 +56,7 @@ static void print_gss_error(OM_uint32 err_maj, OM_uint32 err_min) &status_string); if (GSS_ERROR(maj_stat)) break; - strncpy(buf_maj, (char*) status_string.value, sizeof(buf_maj)); + strfcpy(buf_maj, (char*) status_string.value, sizeof(buf_maj)); gss_release_buffer(&min_stat, &status_string); maj_stat = gss_display_status (&min_stat, @@ -67,7 +67,7 @@ static void print_gss_error(OM_uint32 err_maj, OM_uint32 err_min) &status_string); if (!GSS_ERROR(maj_stat)) { - strncpy(buf_min, (char*) status_string.value, sizeof(buf_min)); + strfcpy(buf_min, (char*) status_string.value, sizeof(buf_min)); gss_release_buffer(&min_stat, &status_string); } } while (!GSS_ERROR(maj_stat) && msg_ctx != 0); diff --git a/init.c b/init.c index 523e7e0c1..f9638123a 100644 --- a/init.c +++ b/init.c @@ -2829,7 +2829,7 @@ static int to_absolute_path(char *path, const char *reference) ref_tmp = safe_strdup(reference); dirpath = dirname(ref_tmp); /* get directory name of */ - strncpy(abs_path, dirpath, PATH_MAX); + strfcpy(abs_path, dirpath, PATH_MAX); safe_strncat(abs_path, sizeof(abs_path), "/", 1); /* append a / at the end of the path */ FREE(&ref_tmp); @@ -2865,7 +2865,7 @@ static int source_rc (const char *rcfile_path, BUFFER *err) pid_t pid; - strncpy(rcfile, rcfile_path, PATH_MAX); + strfcpy(rcfile, rcfile_path, PATH_MAX); rcfilelen = mutt_strlen(rcfile); diff --git a/mutt_notmuch.c b/mutt_notmuch.c index e002ccef6..7e13474d6 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1840,7 +1840,7 @@ bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz) mutt_debug (2, "nm_normalize_uri #2 () -> db_query: %s\n", tmp_ctxdata.db_query); - strncpy(buf, tmp_ctxdata.db_query, sizeof(buf)); + strfcpy(buf, tmp_ctxdata.db_query, sizeof(buf)); if (nm_uri_from_query(&tmp_ctx, buf, sizeof(buf)) == NULL) { diff --git a/send.c b/send.c index b5dacd687..777bc9c97 100644 --- a/send.c +++ b/send.c @@ -287,7 +287,7 @@ static int edit_envelope (ENVELOPE *en, int flags) if (ascii_strncasecmp ("subject:", uh->data, 8) == 0) { p = skip_email_wsp(uh->data + 8); - strncpy (buf, p, sizeof (buf)); + strfcpy (buf, p, sizeof (buf)); } } }