]> granicus.if.org Git - neomutt/commitdiff
coverity: strfcpy
authorRichard Russon <rich@flatcap.org>
Wed, 5 Apr 2017 13:42:50 +0000 (14:42 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 10 Apr 2017 13:31:56 +0000 (14:31 +0100)
Replace strncpy with strfcpy to avoid unterminated strings.

headers.c
imap/auth_gss.c
init.c
mutt_notmuch.c
send.c

index 5f2b6f31577e8d3b260699b822c76d80a8d93d75..cb651816e567497ef21e30b4380d50efb1b99fe0 100644 (file)
--- 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)
index 8f96c9fd4a866fb5cd24d777d50d200ac84b8a8b..5087887363c70d70265e241ffbfb6c7c2e366bf0 100644 (file)
@@ -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 523e7e0c1c1826d7b27fbb00b492c56c7d3e0343..f9638123ac8ca1dfa99c78ff29a36b2eeabdb34a 100644 (file)
--- 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);
 
index e002ccef69ac37431373aa2c500c97edda23d835..7e13474d6a3fe5930a47804b4b885347e4aad14f 100644 (file)
@@ -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 b5dacd687f7927c64b6aee928ae6fa9aaa1e4ad2..777bc9c9763b701ec6d836ebab165545b63c0561 100644 (file)
--- 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));
       }
     }
   }