]> granicus.if.org Git - mutt/commitdiff
Convert pgp_invoke_list_keys and mix_send_message to use BUFFERs.
authorKevin McCarthy <kevin@8t8.us>
Fri, 28 Sep 2018 22:08:19 +0000 (15:08 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 30 Sep 2018 22:43:55 +0000 (15:43 -0700)
Both repetitively perform a lot of copying back in forth, which is
much cleaner with a BUFFER.

Note that in pgp_invoke_list_keys, if there are no hints uids->data
would be NULL.  However, the pgp_invoke() checks and wraps all the
format substitutions with NONULL.

pgpinvoke.c
remailer.c

index aa0efef515221ef154e0b8070dbfa34e1db2e927..9718290969e81e21b34a9b2651f9b61babe0048a 100644 (file)
@@ -342,21 +342,26 @@ pid_t pgp_invoke_list_keys (FILE **pgpin, FILE **pgpout, FILE **pgperr,
                            int pgpinfd, int pgpoutfd, int pgperrfd, 
                            pgp_ring_t keyring, LIST *hints)
 {
-  char uids[HUGE_STRING];
-  char tmpuids[HUGE_STRING];
+  BUFFER *uids;
   char quoted[HUGE_STRING];
-  
-  *uids = '\0';
-  
+  pid_t rc;
+
+  uids = mutt_buffer_new ();
+  mutt_buffer_increase_size (uids, HUGE_STRING);
+
   for (; hints; hints = hints->next)
   {
     mutt_quote_filename (quoted, sizeof (quoted), (char *) hints->data);
-    snprintf (tmpuids, sizeof (tmpuids), "%s %s", uids, quoted);
-    strcpy (uids, tmpuids);    /* __STRCPY_CHECKED__ */
+    mutt_buffer_addstr (uids, quoted);
+    if (hints->next)
+      mutt_buffer_addch (uids, ' ');
   }
 
-  return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
-                    0, NULL, NULL, uids,
+  rc = pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
+                    0, NULL, NULL, uids->data,
                     keyring == PGP_SECRING ? PgpListSecringCommand :
                     PgpListPubringCommand);
+
+  mutt_buffer_free (&uids);
+  return rc;
 }
index f476fdbed566615e7d8675613e5fd8d499f4b6b3..964c5065ed4f7fdab198718317775dfa35938bd8 100644 (file)
@@ -744,24 +744,25 @@ int mix_check_message (HEADER *msg)
 
 int mix_send_message (LIST *chain, const char *tempfile)
 {
-  char cmd[HUGE_STRING];
-  char tmp[HUGE_STRING];
+  BUFFER *cmd;
   char cd_quoted[STRING];
   int i;
 
-  snprintf (cmd, sizeof (cmd), "cat %s | %s -m ", tempfile, Mixmaster);
-  
+  cmd = mutt_buffer_new ();
+  mutt_buffer_increase_size (cmd, HUGE_STRING);
+  mutt_buffer_printf (cmd, "cat %s | %s -m ", tempfile, Mixmaster);
+
   for (i = 0; chain; chain = chain->next, i = 1)
   {
-    strfcpy (tmp, cmd, sizeof (tmp));
+    mutt_buffer_addstr (cmd, i ? "," : " -l ");
     mutt_quote_filename (cd_quoted, sizeof (cd_quoted), (char *) chain->data);
-    snprintf (cmd, sizeof (cmd), "%s%s%s", tmp, i ? "," : " -l ", cd_quoted);
+    mutt_buffer_addstr (cmd, cd_quoted);
   }
 
   if (!option (OPTNOCURSES))
     mutt_endwin (NULL);
-  
-  if ((i = mutt_system (cmd)))
+
+  if ((i = mutt_system (cmd->data)))
   {
     fprintf (stderr, _("Error sending message, child exited %d.\n"), i);
     if (!option (OPTNOCURSES))
@@ -771,9 +772,10 @@ int mix_send_message (LIST *chain, const char *tempfile)
     }
   }
 
+  mutt_buffer_free (&cmd);
   unlink (tempfile);
   return i;
 }
-  
+
 
 #endif