projects
/
mutt
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d4c00c6
)
Convert smime_invoke_import() and helpers to use buffer pool.
master
author
Kevin McCarthy
<kevin@8t8.us>
Sun, 27 Oct 2019 07:47:55 +0000
(15:47 +0800)
committer
Kevin McCarthy
<kevin@8t8.us>
Sun, 27 Oct 2019 07:48:23 +0000
(15:48 +0800)
smime.c
patch
|
blob
|
history
diff --git
a/smime.c
b/smime.c
index 1788e5cd236633e11b7c9eb68ef58fd33eb89851..7a7e87bf7a2fa8f0ca38f963f321503a88428224 100644
(file)
--- a/
smime.c
+++ b/
smime.c
@@
-1046,111
+1046,115
@@
static int smime_handle_cert_email (char *certificate, char *mailbox,
static char *smime_extract_certificate (const char *infile)
{
static char *smime_extract_certificate (const char *infile)
{
- FILE *fp
out = NULL, *fperr
= NULL;
-
char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX]
;
- char
tmpfname[_POSIX_PATH_MAX]
;
+ FILE *fp
err = NULL, *fppk7out = NULL, *fpcertfile
= NULL;
+
BUFFER *tmpfname = NULL, *pk7out = NULL, *certfile = NULL
;
+ char
*retval = NULL
;
pid_t thepid;
int empty;
pid_t thepid;
int empty;
+ tmpfname = mutt_buffer_pool_get ();
+ pk7out = mutt_buffer_pool_get ();
+ certfile = mutt_buffer_pool_get ();
- mutt_
mktemp (tmpfname, sizeof (tmpfname)
);
- if ((fperr = safe_fopen (
tmpfname
, "w+")) == NULL)
+ mutt_
buffer_mktemp (tmpfname
);
+ if ((fperr = safe_fopen (
mutt_b2s (tmpfname)
, "w+")) == NULL)
{
{
- mutt_perror (
tmpfname
);
-
return NULL
;
+ mutt_perror (
mutt_b2s (tmpfname)
);
+
goto cleanup
;
}
}
- mutt_unlink (
tmpfname
);
+ mutt_unlink (
mutt_b2s (tmpfname)
);
- mutt_
mktemp (pk7out, sizeof (pk7out)
);
- if ((fp
out = safe_fopen (pk7out
, "w+")) == NULL)
+ mutt_
buffer_mktemp (pk7out
);
+ if ((fp
pk7out = safe_fopen (mutt_b2s (pk7out)
, "w+")) == NULL)
{
{
- safe_fclose (&fperr);
- mutt_perror (pk7out);
- return NULL;
+ mutt_perror (mutt_b2s (pk7out));
+ goto cleanup;
}
/* Step 1: Convert the signature to a PKCS#7 structure, as we can't
extract the full set of certificates directly.
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
}
/* Step 1: Convert the signature to a PKCS#7 structure, as we can't
extract the full set of certificates directly.
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
- -1, fileno (fpout), fileno (fperr),
+ -1, fileno (fp
pk7
out), fileno (fperr),
infile, NULL, NULL, NULL, NULL, NULL, NULL,
SmimePk7outCommand))== -1)
{
mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
infile, NULL, NULL, NULL, NULL, NULL, NULL,
SmimePk7outCommand))== -1)
{
mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
- safe_fclose (&fperr);
- safe_fclose (&fpout);
- mutt_unlink (pk7out);
- return NULL;
+ goto cleanup;
}
mutt_wait_filter (thepid);
}
mutt_wait_filter (thepid);
- fflush (fpout);
- rewind (fpout);
+ fflush (fp
pk7
out);
+ rewind (fp
pk7
out);
fflush (fperr);
rewind (fperr);
fflush (fperr);
rewind (fperr);
- empty = (fgetc (fpout) == EOF);
+ empty = (fgetc (fp
pk7
out) == EOF);
if (empty)
{
if (empty)
{
- mutt_perror (
pk7out
);
+ mutt_perror (
mutt_b2s (pk7out)
);
mutt_copy_stream (fperr, stdout);
mutt_copy_stream (fperr, stdout);
- safe_fclose (&fpout);
- safe_fclose (&fperr);
- mutt_unlink (pk7out);
- return NULL;
-
+ goto cleanup;
}
}
+ safe_fclose (&fppk7out);
- safe_fclose (&fpout);
- mutt_mktemp (certfile, sizeof (certfile));
- if ((fpout = safe_fopen (certfile, "w+")) == NULL)
+ mutt_buffer_mktemp (certfile);
+ if ((fpcertfile = safe_fopen (mutt_b2s (certfile), "w+")) == NULL)
{
{
- safe_fclose (&fperr);
- mutt_unlink (pk7out);
- mutt_perror (certfile);
- return NULL;
+ mutt_perror (mutt_b2s (certfile));
+ mutt_unlink (mutt_b2s (pk7out));
+ goto cleanup;
}
/* Step 2: Extract the certificates from a PKCS#7 structure.
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
}
/* Step 2: Extract the certificates from a PKCS#7 structure.
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
- -1, fileno (fp
out
), fileno (fperr),
-
pk7out
, NULL, NULL, NULL, NULL, NULL, NULL,
+ -1, fileno (fp
certfile
), fileno (fperr),
+
mutt_b2s (pk7out)
, NULL, NULL, NULL, NULL, NULL, NULL,
SmimeGetCertCommand))== -1)
{
mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
SmimeGetCertCommand))== -1)
{
mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
- safe_fclose (&fperr);
- safe_fclose (&fpout);
- mutt_unlink (pk7out);
- mutt_unlink (certfile);
- return NULL;
+ mutt_unlink (mutt_b2s (pk7out));
+ goto cleanup;
}
mutt_wait_filter (thepid);
}
mutt_wait_filter (thepid);
- mutt_unlink (
pk7out
);
+ mutt_unlink (
mutt_b2s (pk7out)
);
- fflush (fp
out
);
- rewind (fp
out
);
+ fflush (fp
certfile
);
+ rewind (fp
certfile
);
fflush (fperr);
rewind (fperr);
fflush (fperr);
rewind (fperr);
- empty = (fgetc (fp
out
) == EOF);
+ empty = (fgetc (fp
certfile
) == EOF);
if (empty)
{
mutt_copy_stream (fperr, stdout);
if (empty)
{
mutt_copy_stream (fperr, stdout);
- safe_fclose (&fpout);
- safe_fclose (&fperr);
- mutt_unlink (certfile);
- return NULL;
+ goto cleanup;
}
}
- safe_fclose (&fpout);
- safe_fclose (&fperr);
+ safe_fclose (&fpcertfile);
- return safe_strdup (certfile);
+ retval = safe_strdup (mutt_b2s (certfile));
+
+cleanup:
+ safe_fclose (&fperr);
+ if (fppk7out)
+ {
+ safe_fclose (&fppk7out);
+ mutt_unlink (mutt_b2s (pk7out));
+ }
+ if (fpcertfile)
+ {
+ safe_fclose (&fpcertfile);
+ mutt_unlink (mutt_b2s (certfile));
+ }
+ mutt_buffer_pool_release (&tmpfname);
+ mutt_buffer_pool_release (&pk7out);
+ mutt_buffer_pool_release (&certfile);
+ return retval;
}
static char *smime_extract_signer_certificate (const char *infile)
}
static char *smime_extract_signer_certificate (const char *infile)
@@
-1228,26
+1232,31
@@
cleanup:
void smime_invoke_import (const char *infile, const char *mailbox)
{
void smime_invoke_import (const char *infile, const char *mailbox)
{
- char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING];
+ BUFFER *tmpfname;
+ char *certfile = NULL, buf[STRING];
FILE *smimein=NULL, *fpout = NULL, *fperr = NULL;
pid_t thepid=-1;
FILE *smimein=NULL, *fpout = NULL, *fperr = NULL;
pid_t thepid=-1;
- mutt_mktemp (tmpfname, sizeof (tmpfname));
- if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
+ tmpfname = mutt_buffer_pool_get ();
+ mutt_buffer_mktemp (tmpfname);
+ if ((fperr = safe_fopen (mutt_b2s (tmpfname), "w+")) == NULL)
{
{
- mutt_perror (tmpfname);
+ mutt_perror (mutt_b2s (tmpfname));
+ mutt_buffer_pool_release (&tmpfname);
return;
}
return;
}
- mutt_unlink (
tmpfname
);
+ mutt_unlink (
mutt_b2s (tmpfname)
);
- mutt_
mktemp (tmpfname, sizeof (tmpfname)
);
- if ((fpout = safe_fopen (
tmpfname
, "w+")) == NULL)
+ mutt_
buffer_mktemp (tmpfname
);
+ if ((fpout = safe_fopen (
mutt_b2s (tmpfname)
, "w+")) == NULL)
{
{
+ mutt_perror (mutt_b2s (tmpfname));
safe_fclose (&fperr);
safe_fclose (&fperr);
- mutt_
perror (
tmpfname);
+ mutt_
buffer_pool_release (&
tmpfname);
return;
}
return;
}
- mutt_unlink (tmpfname);
+ mutt_unlink (mutt_b2s (tmpfname));
+ mutt_buffer_pool_release (&tmpfname);
buf[0] = '\0';
buf[0] = '\0';