From: Kevin McCarthy Date: Fri, 28 Sep 2018 22:08:19 +0000 (-0700) Subject: Convert pgp_invoke_list_keys and mix_send_message to use BUFFERs. X-Git-Tag: mutt-1-11-rel~58 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3e0742a07505b0330a8eac166ec33c578fdda0a;p=mutt Convert pgp_invoke_list_keys and mix_send_message to use BUFFERs. 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. --- diff --git a/pgpinvoke.c b/pgpinvoke.c index aa0efef5..97182909 100644 --- a/pgpinvoke.c +++ b/pgpinvoke.c @@ -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; } diff --git a/remailer.c b/remailer.c index f476fdbe..964c5065 100644 --- a/remailer.c +++ b/remailer.c @@ -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