]> granicus.if.org Git - neomutt/commitdiff
replace strncpy with strfcpy
authorRichard Russon <rich@flatcap.org>
Fri, 5 Oct 2018 22:04:14 +0000 (23:04 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 6 Oct 2018 10:57:09 +0000 (11:57 +0100)
strncpy isn't guaranteed to NUL-terminate strings

browser.c
curs_main.c
edit.c
imap/imap.c
menu.c
ncrypt/gnupgparse.c
nntp/newsrc.c
notmuch/mutt_notmuch.c

index 6b78180824eacb5ac8cbe13c42717fb47a65f683..110dbc77be8a3d6bead5be3327c016f703c9dfc1 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -632,7 +632,7 @@ static const char *group_index_format_str(char *buf, size_t buflen, size_t col,
       break;
 
     case 'f':
-      strncpy(fn, folder->ff->name, sizeof(fn) - 1);
+      mutt_str_strfcpy(fn, folder->ff->name, sizeof(fn));
       snprintf(fmt, sizeof(fmt), "%%%ss", prec);
       snprintf(buf, buflen, fmt, fn);
       break;
index f5d11e88d0bdd0a169c3e6d83ffddba5d822a9bf..f18228e1be32f226ea6fba15515d17233d89673f 100644 (file)
@@ -2070,7 +2070,7 @@ int mutt_index_menu(void)
           break;
         }
         nm_query_window_backward();
-        strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
+        mutt_str_strfcpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
         if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf)))
           mutt_message(_("Failed to create query, aborting"));
         else
@@ -2089,7 +2089,7 @@ int mutt_index_menu(void)
           break;
         }
         nm_query_window_forward();
-        strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
+        mutt_str_strfcpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
         if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf)))
           mutt_message(_("Failed to create query, aborting"));
         else
@@ -2150,7 +2150,7 @@ int mutt_index_menu(void)
           const char *path = mutt_sb_get_highlight();
           if (!path || !*path)
             break;
-          strncpy(buf, path, sizeof(buf));
+          mutt_str_strfcpy(buf, path, sizeof(buf));
 
           /* Mark the selected dir for the neomutt browser */
           mutt_browser_select_dir(buf);
diff --git a/edit.c b/edit.c
index f9302bdc0b0e5632d699af6594fe45a3b89a3a69..529ada1f55815218c1c6a95485815c53aa859fcc 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -483,7 +483,7 @@ int mutt_builtin_editor(const char *path, struct Email *msg, struct Email *cur)
         case 'r':
           if (*p)
           {
-            strncpy(tmp, p, sizeof(tmp));
+            mutt_str_strfcpy(tmp, p, sizeof(tmp));
             mutt_expand_path(tmp, sizeof(tmp));
             buf = be_snarf_file(tmp, buf, &bufmax, &buflen, true);
           }
index 642f8ee84a28e86678a7603c1a0e1ba122f0c29f..545f70e39e9940f6cb9197048c96363e579ab7db 100644 (file)
@@ -2608,7 +2608,7 @@ static int imap_tags_edit(struct Context *ctx, const char *tags, char *buf, size
 
   *buf = '\0';
   if (tags)
-    strncpy(buf, tags, buflen);
+    mutt_str_strfcpy(buf, tags, buflen);
 
   if (mutt_get_field("Tags: ", buf, buflen, 0) != 0)
     return -1;
diff --git a/menu.c b/menu.c
index 795c551150a428429c5ce28ae357874af07e9c97..82abd7db9a48fa5e6f232e3608d5efe4b3aed72f 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -317,7 +317,7 @@ static void menu_make_entry(char *buf, size_t buflen, struct Menu *menu, int i)
 {
   if (menu->dialog)
   {
-    strncpy(buf, menu->dialog[i], buflen);
+    mutt_str_strfcpy(buf, menu->dialog[i], buflen);
     menu->current = -1; /* hide menubar */
   }
   else
index 9ec5090c510b8bb3b589bf6e47e84e2b5b75aa60..d6d53364d9751308de89a1019c6b6a709d3f87f8 100644 (file)
@@ -268,7 +268,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe
         time.tm_sec = 0;
         time.tm_min = 0;
         time.tm_hour = 12;
-        strncpy(tstr, p, 11);
+        mutt_str_strfcpy(tstr, p, sizeof(tstr));
         tstr[4] = '\0';
         tstr[7] = '\0';
         if (mutt_str_atoi(tstr, &time.tm_year) < 0)
index 7b09a9d9349c3b80891d4bb09056f88210c6a8ca..de772469089bafa2ae47d980e86fa8ea29933ddf 100644 (file)
@@ -971,7 +971,7 @@ const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char
       }
       break;
     case 's':
-      strncpy(fn, acct->host, sizeof(fn) - 1);
+      mutt_str_strfcpy(fn, acct->host, sizeof(fn));
       mutt_str_strlower(fn);
       snprintf(fmt, sizeof(fmt), "%%%ss", prec);
       snprintf(buf, buflen, fmt, fn);
index 238c8cbae04e1def5eded3e041351831d2d75dc8..08bf26ded4c203218518ee2f7b2cdacfce68cb45 100644 (file)
@@ -1938,7 +1938,7 @@ char *nm_uri_from_query(struct Mailbox *mailbox, char *buf, size_t buflen)
 
   url_pct_encode(&uri[added], sizeof(uri) - added, buf);
 
-  strncpy(buf, uri, buflen);
+  mutt_str_strfcpy(buf, uri, buflen);
   buf[buflen - 1] = '\0';
 
   mutt_debug(1, "nm: uri from query '%s'\n", buf);
@@ -1988,7 +1988,7 @@ bool nm_normalize_uri(const char *uri, char *buf, size_t buflen)
   if (!nm_uri_from_query(&tmp_mbox, tmp, sizeof(tmp)))
     goto gone;
 
-  strncpy(buf, tmp, buflen);
+  mutt_str_strfcpy(buf, tmp, buflen);
 
   mutt_debug(2, "#3 (%s) -> %s\n", uri, buf);
 
@@ -2243,7 +2243,7 @@ int nm_description_to_path(const char *desc, char *buf, size_t buflen)
   {
     if ((np->m->magic == MUTT_NOTMUCH) && np->m->desc && (strcmp(desc, np->m->desc) == 0))
     {
-      strncpy(buf, np->m->path, buflen);
+      mutt_str_strfcpy(buf, np->m->path, buflen);
       buf[buflen - 1] = '\0';
       return 0;
     }
@@ -2585,7 +2585,7 @@ static int nm_mbox_sync(struct Context *ctx, int *index_hint)
 
     if (edata->oldpath)
     {
-      strncpy(old, edata->oldpath, sizeof(old));
+      mutt_str_strfcpy(old, edata->oldpath, sizeof(old));
       old[sizeof(old) - 1] = '\0';
       mutt_debug(2, "nm: fixing obsolete path '%s'\n", old);
     }