From: Kevin McCarthy Date: Thu, 26 Sep 2019 01:44:50 +0000 (-0700) Subject: Convert crypt_extract_keys and signed handler to use buffers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13965f79fbd4179d72185fa8d39178474b711115;p=mutt Convert crypt_extract_keys and signed handler to use buffers. --- diff --git a/crypt-mod-smime-classic.c b/crypt-mod-smime-classic.c index f906690c..acce9fc7 100644 --- a/crypt-mod-smime-classic.c +++ b/crypt-mod-smime-classic.c @@ -81,7 +81,7 @@ static BODY *crypt_mod_smime_build_smime_entity (BODY *a, char *certlist) return smime_build_smime_entity (a, certlist); } -static void crypt_mod_smime_invoke_import (char *infile, char *mailbox) +static void crypt_mod_smime_invoke_import (const char *infile, const char *mailbox) { smime_invoke_import (infile, mailbox); } diff --git a/crypt-mod.h b/crypt-mod.h index 08934a63..1a03e1fc 100644 --- a/crypt-mod.h +++ b/crypt-mod.h @@ -62,7 +62,7 @@ typedef int (*crypt_func_smime_verify_sender_t) (HEADER *h); typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY *a, char *certlist); -typedef void (*crypt_func_smime_invoke_import_t) (char *infile, char *mailbox); +typedef void (*crypt_func_smime_invoke_import_t) (const char *infile, const char *mailbox); typedef void (*crypt_func_init_t) (void); diff --git a/crypt.c b/crypt.c index 7eff2d19..3e9d0449 100644 --- a/crypt.c +++ b/crypt.c @@ -727,18 +727,20 @@ void convert_to_7bit (BODY *a) void crypt_extract_keys_from_messages (HEADER * h) { int i; - char tempfname[_POSIX_PATH_MAX], *mbox; + BUFFER *tempfname = NULL; + char *mbox; ADDRESS *tmp = NULL; FILE *fpout; if (!WithCrypto) return; - mutt_mktemp (tempfname, sizeof (tempfname)); - if (!(fpout = safe_fopen (tempfname, "w"))) + tempfname = mutt_buffer_pool_get (); + mutt_buffer_mktemp (tempfname); + if (!(fpout = safe_fopen (mutt_b2s (tempfname), "w"))) { - mutt_perror (tempfname); - return; + mutt_perror (mutt_b2s (tempfname)); + goto cleanup; } if ((WithCrypto & APPLICATION_PGP)) @@ -766,7 +768,7 @@ void crypt_extract_keys_from_messages (HEADER * h) fflush(fpout); mutt_endwin (_("Trying to extract PGP keys...\n")); - crypt_pgp_invoke_import (tempfname); + crypt_pgp_invoke_import (mutt_b2s (tempfname)); } if ((WithCrypto & APPLICATION_SMIME) @@ -789,7 +791,7 @@ void crypt_extract_keys_from_messages (HEADER * h) if (mbox) { mutt_endwin (_("Trying to extract S/MIME certificates...\n")); - crypt_smime_invoke_import (tempfname, mbox); + crypt_smime_invoke_import (mutt_b2s (tempfname), mbox); tmp = NULL; } } @@ -809,7 +811,7 @@ void crypt_extract_keys_from_messages (HEADER * h) mutt_copy_message (fpout, Context, h, MUTT_CM_DECODE|MUTT_CM_CHARCONV, 0); fflush(fpout); mutt_endwin (_("Trying to extract PGP keys...\n")); - crypt_pgp_invoke_import (tempfname); + crypt_pgp_invoke_import (mutt_b2s (tempfname)); } if ((WithCrypto & APPLICATION_SMIME) @@ -829,7 +831,7 @@ void crypt_extract_keys_from_messages (HEADER * h) if (mbox) /* else ? */ { mutt_message (_("Trying to extract S/MIME certificates...\n")); - crypt_smime_invoke_import (tempfname, mbox); + crypt_smime_invoke_import (mutt_b2s (tempfname), mbox); } } } @@ -839,10 +841,13 @@ void crypt_extract_keys_from_messages (HEADER * h) if (isendwin()) mutt_any_key_to_continue (NULL); - mutt_unlink (tempfname); + mutt_unlink (mutt_b2s (tempfname)); if ((WithCrypto & APPLICATION_PGP)) unset_option (OPTDONTHANDLEPGPKEYS); + +cleanup: + mutt_buffer_pool_release (&tempfname); } @@ -1011,7 +1016,7 @@ int mutt_protected_headers_handler (BODY *a, STATE *s) int mutt_signed_handler (BODY *a, STATE *s) { - char tempfile[_POSIX_PATH_MAX]; + BUFFER *tempfile = NULL; int signed_type; int inconsistent = 0; @@ -1078,8 +1083,9 @@ int mutt_signed_handler (BODY *a, STATE *s) if (sigcnt) { - mutt_mktemp (tempfile, sizeof (tempfile)); - if (crypt_write_signed (a, s, tempfile) == 0) + tempfile = mutt_buffer_pool_get (); + mutt_buffer_mktemp (tempfile); + if (crypt_write_signed (a, s, mutt_b2s (tempfile)) == 0) { for (i = 0; i < sigcnt; i++) { @@ -1087,7 +1093,7 @@ int mutt_signed_handler (BODY *a, STATE *s) && signatures[i]->type == TYPEAPPLICATION && !ascii_strcasecmp (signatures[i]->subtype, "pgp-signature")) { - if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0) + if (crypt_pgp_verify_one (signatures[i], s, mutt_b2s (tempfile)) != 0) goodsig = 0; continue; @@ -1098,7 +1104,7 @@ int mutt_signed_handler (BODY *a, STATE *s) && (!ascii_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature") || !ascii_strcasecmp(signatures[i]->subtype, "pkcs7-signature"))) { - if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0) + if (crypt_smime_verify_one (signatures[i], s, mutt_b2s (tempfile)) != 0) goodsig = 0; continue; @@ -1110,7 +1116,8 @@ int mutt_signed_handler (BODY *a, STATE *s) } } - mutt_unlink (tempfile); + mutt_unlink (mutt_b2s (tempfile)); + mutt_buffer_pool_release (&tempfile); b->goodsig = goodsig; b->badsig = !goodsig; diff --git a/cryptglue.c b/cryptglue.c index ec4d0513..d0e03167 100644 --- a/cryptglue.c +++ b/cryptglue.c @@ -434,7 +434,7 @@ BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist) } /* Add a certificate and update index file (externally). */ -void crypt_smime_invoke_import (char *infile, char *mailbox) +void crypt_smime_invoke_import (const char *infile, const char *mailbox) { if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import)) (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox); diff --git a/mutt_crypt.h b/mutt_crypt.h index 28f70ee9..4f20e7da 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -297,7 +297,7 @@ BODY *crypt_smime_sign_message (BODY *a); BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist); /* Add a certificate and update index file (externally). */ -void crypt_smime_invoke_import (char *infile, char *mailbox); +void crypt_smime_invoke_import (const char *infile, const char *mailbox); int crypt_smime_send_menu (HEADER *msg); diff --git a/smime.c b/smime.c index a8909121..141d0930 100644 --- a/smime.c +++ b/smime.c @@ -1037,7 +1037,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, -static char *smime_extract_certificate (char *infile) +static char *smime_extract_certificate (const char *infile) { FILE *fpout = NULL, *fperr = NULL; char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX]; @@ -1216,7 +1216,7 @@ static char *smime_extract_signer_certificate (char *infile) /* Add a certificate and update index file (externally). */ -void smime_invoke_import (char *infile, char *mailbox) +void smime_invoke_import (const char *infile, const char *mailbox) { char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING]; FILE *smimein=NULL, *fpout = NULL, *fperr = NULL; diff --git a/smime.h b/smime.h index 853f2b3f..2bd36d35 100644 --- a/smime.h +++ b/smime.h @@ -61,7 +61,7 @@ smime_key_t *smime_ask_for_key(char *, short, short); char *smime_findKeys (ADDRESS *adrlist, int oppenc_mode); -void smime_invoke_import (char *, char *); +void smime_invoke_import (const char *, const char *); int smime_send_menu (HEADER *msg);