]> granicus.if.org Git - neomutt/commitdiff
Make sure Progress doesn't reference an out-of-scope buffer 1820/head
authorPietro Cerutti <gahr@gahr.ch>
Thu, 29 Aug 2019 09:46:29 +0000 (09:46 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 29 Aug 2019 11:59:42 +0000 (12:59 +0100)
Cleanup mutt_progress_init's callers

Fixes: #1819
index.c
maildir/shared.c
mbox/mbox.c
notmuch/mutt_notmuch.c
progress.c
progress.h

diff --git a/index.c b/index.c
index 115be7ef6a9ef7d4c4c5c900651ef1a0b0d76384..29f72c098d07df33d6e4039be78878b34fc0d224 100644 (file)
--- a/index.c
+++ b/index.c
@@ -2058,10 +2058,8 @@ int mutt_index_menu(void)
 
           if (!Context->mailbox->quiet)
           {
-            char msgbuf[256];
-            snprintf(msgbuf, sizeof(msgbuf), _("Update tags..."));
-            mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, 1,
-                               Context->mailbox->msg_tagged);
+            mutt_progress_init(&progress, _("Update tags..."), MUTT_PROGRESS_MSG,
+                               1, Context->mailbox->msg_tagged);
           }
 
 #ifdef USE_NOTMUCH
index 2c90b84b1ef84fa8a53b89c85c0ea4e02be82a28..f57cdac5d82ccc8a2f36a8637fe5a224525be2c3 100644 (file)
@@ -802,13 +802,13 @@ int mh_read_dir(struct Mailbox *m, const char *subdir)
   struct Maildir *md = NULL;
   struct MhSequences mhs = { 0 };
   struct Maildir **last = NULL;
-  char msgbuf[256];
   struct Progress progress;
 
   if (!m->quiet)
   {
-    snprintf(msgbuf, sizeof(msgbuf), _("Scanning %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Scanning %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_ReadInc, 0);
   }
 
   struct MaildirMboxData *mdata = maildir_mdata_get(m);
@@ -829,8 +829,9 @@ int mh_read_dir(struct Mailbox *m, const char *subdir)
 
   if (!m->quiet)
   {
-    snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, count);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Reading %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_ReadInc, count);
   }
   maildir_delayed_parsing(m, &md, &progress);
 
@@ -1691,7 +1692,6 @@ int mh_mbox_sync(struct Mailbox *m, int *index_hint)
 
   int i, j;
   header_cache_t *hc = NULL;
-  char msgbuf[PATH_MAX + 64];
   struct Progress progress;
 
   if (m->magic == MUTT_MH)
@@ -1709,8 +1709,9 @@ int mh_mbox_sync(struct Mailbox *m, int *index_hint)
 
   if (!m->quiet)
   {
-    snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Writing %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
   }
 
   for (i = 0; i < m->msg_count; i++)
index d243d48ecf0dd6d4513005ce24d62c88e3916a74..0f008cbed83026a4bf01957174611641e1357836 100644 (file)
@@ -212,9 +212,9 @@ static int mmdf_parse_mailbox(struct Mailbox *m)
 
   if (!m->quiet)
   {
-    char msgbuf[256];
-    snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Reading %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_ReadInc, 0);
   }
 
   while (true)
@@ -378,9 +378,9 @@ static int mbox_parse_mailbox(struct Mailbox *m)
 
   if (!m->quiet)
   {
-    char msgbuf[256];
-    snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Reading %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_ReadInc, 0);
   }
 
   if (!m->emails)
@@ -1130,7 +1130,6 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint)
   struct MUpdate *old_offset = NULL;
   FILE *fp = NULL;
   struct Progress progress;
-  char msgbuf[PATH_MAX + 64];
 
   /* sort message by their position in the mailbox on disk */
   if (C_Sort != SORT_ORDER)
@@ -1224,8 +1223,9 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint)
 
   if (!m->quiet)
   {
-    snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Writing %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
   }
 
   for (i = first, j = 0; i < m->msg_count; i++)
index 6bd769e3cb2bdb9dfbc7585e35b00115854ba024..ccbef66a93c54d29414a3cc767269829939a61af 100644 (file)
@@ -854,12 +854,9 @@ static void progress_update(struct Mailbox *m, notmuch_query_t *q)
 
   if (!mdata->progress_ready && q)
   {
-    static char msg[256];
-    snprintf(msg, sizeof(msg), _("Reading messages..."));
-
     // The total mail count is in oldmsgcount, so use that instead of recounting.
-    mutt_progress_init(&mdata->progress, msg, MUTT_PROGRESS_MSG, C_ReadInc,
-                       mdata->oldmsgcount);
+    mutt_progress_init(&mdata->progress, _("Reading messages..."),
+                       MUTT_PROGRESS_MSG, C_ReadInc, mdata->oldmsgcount);
     mdata->progress_ready = true;
   }
 
@@ -2362,10 +2359,10 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint)
 
   if (!m->quiet)
   {
-    char msgbuf[PATH_MAX + 64];
     /* all is in this function so we don't use data->progress here */
-    snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mailbox_path(m));
-    mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
+    char msg[PATH_MAX];
+    snprintf(msg, sizeof(msg), _("Writing %s..."), mailbox_path(m));
+    mutt_progress_init(&progress, msg, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count);
   }
 
   header_cache_t *h = nm_hcache_open(m);
index 5563769ca509e4fd3bab040dc47e491cab94456b..da3956ec321c41c1b687c1bdf963ec3fed6b5041 100644 (file)
@@ -107,7 +107,7 @@ static void message_bar(int percent, const char *fmt, ...)
 /**
  * mutt_progress_init - Set up a progress bar
  * @param progress Progress bar
- * @param msg      Message to display
+ * @param msg      Message to display; this is copied into the Progress object
  * @param flags    Flags, e.g. #MUTT_PROGRESS_SIZE
  * @param inc      Increments to display (0 disables updates)
  * @param size     Total size of expected file / traffic
@@ -125,7 +125,7 @@ void mutt_progress_init(struct Progress *progress, const char *msg,
   memset(progress, 0, sizeof(struct Progress));
   progress->inc = inc;
   progress->flags = flags;
-  progress->msg = msg;
+  mutt_str_strfcpy(progress->msg, msg, sizeof(progress->msg));
   progress->size = size;
   if (progress->size != 0)
   {
index 819f799ce5d99792d5610e42ecc741594eb3dc3b..b025bd8df3d97248e49d14012ebebdff83942354 100644 (file)
@@ -38,7 +38,7 @@ struct Progress
 {
   unsigned short inc;
   unsigned short flags;
-  const char *msg;
+  char msg[1024];
   long pos;
   size_t size;
   unsigned int timestamp;