From: Rocco Rutte Date: Sun, 15 Mar 2009 12:46:52 +0000 (+0100) Subject: Use safe_fclose() instead of fclose(), add fclose() to check_sec.sh X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cfd92192fbe9b2c17fdc2b262592a486025d0ff;p=mutt Use safe_fclose() instead of fclose(), add fclose() to check_sec.sh --- diff --git a/ChangeLog b/ChangeLog index 1d89f175..442798f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-03-10 18:39 +0100 NONAKA Kimihiro (cc6fede605d4) + + * ChangeLog, mh.c: Fix crashes with 64bit time_t. Closes #3184. + 2009-03-09 12:04 +0100 Vincent Lefevre (4ce562b7f5d7) * mbyte.h: Unbreak compilation on OS X with --with-regex/--without-wc- diff --git a/alias.c b/alias.c index 9128372f..1de2bf4e 100644 --- a/alias.c +++ b/alias.c @@ -378,7 +378,7 @@ retry_name: recode_buf (buf, sizeof (buf)); write_safe_address (rc, buf); fputc ('\n', rc); - fclose (rc); + safe_fclose (&rc); mutt_message _("Alias added."); } else @@ -388,7 +388,7 @@ retry_name: fseek_err: mutt_perror (_("Error seeking in alias file")); - fclose(rc); + safe_fclose (&rc); return; } diff --git a/attach.c b/attach.c index 5acc17b3..9e99e924 100644 --- a/attach.c +++ b/attach.c @@ -76,8 +76,8 @@ int mutt_get_tmp_attachment (BODY *a) else mutt_perror(fpin ? tempfile : a->filename); - if(fpin) fclose(fpin); - if(fpout) fclose(fpout); + if(fpin) safe_fclose (&fpin); + if(fpout) safe_fclose (&fpout); return a->unlink ? 0 : -1; } @@ -176,8 +176,8 @@ int mutt_compose_attachment (BODY *a) goto bailout; } mutt_copy_stream (fp, tfp); - fclose (fp); - fclose (tfp); + safe_fclose (&fp); + safe_fclose (&tfp); mutt_unlink (a->filename); if (mutt_rename_file (tempfile, a->filename) != 0) { @@ -884,7 +884,7 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, if (stat (m->filename, &st) == -1) { mutt_perror ("stat"); - fclose (s.fpout); + safe_fclose (&s.fpout); return (-1); } @@ -915,7 +915,7 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, mutt_body_handler (m, &s); - fclose (s.fpout); + safe_fclose (&s.fpout); if (fp == NULL) { m->length = 0; @@ -926,7 +926,7 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, m->parts = saved_parts; m->hdr = saved_hdr; } - fclose (s.fpin); + safe_fclose (&s.fpin); } return (0); diff --git a/buffy.c b/buffy.c index db20c218..c5578504 100644 --- a/buffy.c +++ b/buffy.c @@ -128,7 +128,7 @@ static int test_new_folder (const char *path) if ((f = fopen (path, "rb"))) { rc = test_last_status_new (f); - fclose (f); + safe_fclose (&f); } return rc; diff --git a/check_sec.sh b/check_sec.sh index f8a73e5c..c4505a3a 100755 --- a/check_sec.sh +++ b/check_sec.sh @@ -31,6 +31,7 @@ do_check () } do_check '\content = mutt_make_file_attach (fname)) == NULL) { diff --git a/copy.c b/copy.c index fa283200..95e12aed 100644 --- a/copy.c +++ b/copy.c @@ -633,12 +633,12 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, fseeko (fp, cur->offset, 0); if (mutt_copy_bytes (fp, fpout, cur->length) == -1) { - fclose (fp); + safe_fclose (&fp); mutt_free_body (&cur); return (-1); } mutt_free_body (&cur); - fclose (fp); + safe_fclose (&fp); } else { diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 8aac3dda..244293f5 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -440,12 +440,12 @@ static gpgme_data_t body_to_data_object (BODY *a, int convert) buf[0] = c; gpgme_data_write (data, buf, 1); } - fclose(fptmp); + safe_fclose (&fptmp); gpgme_data_seek (data, 0, SEEK_SET); } else { - fclose(fptmp); + safe_fclose (&fptmp); err = gpgme_data_new_from_file (&data, tempfile, 1); } unlink (tempfile); @@ -544,7 +544,7 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE **ret_fp) if (fwrite (buf, nread, 1, fp) != 1) { mutt_perror (tempfile); - fclose (fp); + safe_fclose (&fp); unlink (tempfile); return NULL; } @@ -553,12 +553,12 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE **ret_fp) if (ret_fp) rewind (fp); else - fclose (fp); + safe_fclose (&fp); if (nread == -1) { mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err)); unlink (tempfile); - fclose (fp); + safe_fclose (&fp); return NULL; } if (ret_fp) @@ -1788,7 +1788,7 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) b->type = saved_b_type; b->length = saved_b_length; b->offset = saved_b_offset; - fclose (tmpfp); + safe_fclose (&tmpfp); rewind (*fpout); if (*cur && !is_signed && !(*cur)->parts && mutt_is_application_smime (*cur)) { @@ -1824,7 +1824,7 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) bb->length = ftello (s.fpout); bb->offset = 0; rewind (tmpfp); - fclose (*fpout); + safe_fclose (fpout); memset (&s, 0, sizeof (s)); s.fpin = tmpfp; @@ -1843,7 +1843,7 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) bb->type = saved_b_type; bb->length = saved_b_length; bb->offset = saved_b_offset; - fclose (tmpfp); + safe_fclose (&tmpfp); rewind (*fpout); mutt_free_body (cur); *cur = tmp_b; @@ -1956,10 +1956,7 @@ static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun) err_fp: if (rc) - { - fclose (*fp); - *fp = NULL; - } + safe_fclose (fp); err_tmpdir: if (dryrun) mutt_rmtree (tmpdir); @@ -2068,7 +2065,7 @@ void pgp_gpgme_invoke_import (const char *fname) dprint (1, (debugfile, "error converting key file into data object\n")); return; } - fclose (in); + safe_fclose (&in); if (!pgp_gpgme_extract_keys (keydata, &out, 0)) { @@ -2076,7 +2073,7 @@ void pgp_gpgme_invoke_import (const char *fname) outlen = ftell (out); fseek (out, 0, SEEK_SET); mutt_copy_bytes (out, stdout, outlen); - fclose (out); + safe_fclose (&out); } else printf (_("Error extracting key data!\n")); @@ -2150,7 +2147,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE *s, char *charset) } fgetconv_close (&fc); - fclose (fp); + safe_fclose (&fp); } @@ -2476,7 +2473,7 @@ int pgp_gpgme_encrypted_handler (BODY *a, STATE *s) mutt_free_body (&tattach); } - fclose (fpout); + safe_fclose (&fpout); mutt_unlink(tempfile); dprint (2, (debugfile, "Leaving pgp_encrypted handler\n")); @@ -2550,7 +2547,7 @@ int smime_gpgme_application_handler (BODY *a, STATE *s) mutt_free_body (&tattach); } - fclose (fpout); + safe_fclose (&fpout); mutt_unlink(tempfile); dprint (2, (debugfile, "Leaving smime_encrypted handler\n")); @@ -3506,7 +3503,7 @@ verify_key (crypt_key_t *key) leave: gpgme_key_release (k); gpgme_release (listctx); - fclose (fp); + safe_fclose (&fp); mutt_clear_error (); snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), crypt_keyid (key)); mutt_do_pager (cmd, tempfile, 0, NULL); diff --git a/crypt.c b/crypt.c index eb2c3e01..60b594d0 100644 --- a/crypt.c +++ b/crypt.c @@ -538,7 +538,7 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempfile) fputc (c, fp); } - fclose (fp); + safe_fclose (&fp); return 0; } @@ -613,7 +613,7 @@ void crypt_extract_keys_from_messages (HEADER * h) if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]->security)) { - fclose (fpout); + safe_fclose (&fpout); break; } @@ -695,7 +695,7 @@ void crypt_extract_keys_from_messages (HEADER * h) } } - fclose (fpout); + safe_fclose (&fpout); if (isendwin()) mutt_any_key_to_continue (NULL); diff --git a/edit.c b/edit.c index d952e9a2..35e45e47 100644 --- a/edit.c +++ b/edit.c @@ -109,7 +109,7 @@ be_snarf_file (const char *path, char **buf, int *max, int *len, int verbose) snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) sb.st_size); addstr(tmp); } - fclose (f); + safe_fclose (&f); } else { diff --git a/editmsg.c b/editmsg.c index 85b75e31..ecba7544 100644 --- a/editmsg.c +++ b/editmsg.c @@ -191,7 +191,7 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) mx_close_mailbox (&tmpctx, NULL); bail: - if (fp) fclose (fp); + if (fp) safe_fclose (&fp); if (rc >= 0) unlink (tmp); diff --git a/gnupgparse.c b/gnupgparse.c index 0bfb1983..b7740d50 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -373,7 +373,7 @@ pgp_key_t pgp_get_candidates (pgp_ring_t keyring, LIST * hints) if (ferror (fp)) mutt_perror ("fgets"); - fclose (fp); + safe_fclose (&fp); mutt_wait_filter (thepid); close (devnull); diff --git a/handler.c b/handler.c index 508aec47..c3572bd3 100644 --- a/handler.c +++ b/handler.c @@ -1643,7 +1643,7 @@ int mutt_body_handler (BODY *b, STATE *s) { b->length = ftello (s->fpout); b->offset = 0; - fclose (s->fpout); + safe_fclose (&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1674,7 +1674,7 @@ int mutt_body_handler (BODY *b, STATE *s) b->offset = tmpoffset; /* restore the original source stream */ - fclose (s->fpin); + safe_fclose (&s->fpin); s->fpin = fp; } } diff --git a/headers.c b/headers.c index 8d4a3aa5..7a102b05 100644 --- a/headers.c +++ b/headers.c @@ -64,8 +64,8 @@ void mutt_edit_headers (const char *editor, mutt_copy_stream (ifp, ofp); - fclose (ifp); - fclose (ofp); + safe_fclose (&ifp); + safe_fclose (&ofp); if (stat (path, &st) == -1) { @@ -98,7 +98,7 @@ void mutt_edit_headers (const char *editor, if ((ofp = safe_fopen (body, "w")) == NULL) { /* intentionally leak a possible temporary file here */ - fclose (ifp); + safe_fclose (&ifp); mutt_perror (body); return; } @@ -106,8 +106,8 @@ void mutt_edit_headers (const char *editor, n = mutt_read_rfc822_header (ifp, NULL, 1, 0); while ((i = fread (buffer, 1, sizeof (buffer), ifp)) > 0) fwrite (buffer, 1, i, ofp); - fclose (ofp); - fclose (ifp); + safe_fclose (&ofp); + safe_fclose (&ifp); mutt_unlink (path); /* restore old info. */ diff --git a/help.c b/help.c index b0d50f6f..10ad9cf2 100644 --- a/help.c +++ b/help.c @@ -367,7 +367,7 @@ void mutt_help (int menu) if (menu != MENU_PAGER) dump_unbound (f, OpGeneric, Keymaps[MENU_GENERIC], Keymaps[menu]); - fclose (f); + safe_fclose (&f); snprintf (buf, sizeof (buf), _("Help for %s"), desc); } diff --git a/history.c b/history.c index f8702d45..6585aa33 100644 --- a/history.c +++ b/history.c @@ -90,7 +90,7 @@ void mutt_read_histfile (void) } } - fclose (f); + safe_fclose (&f); FREE (&linebuf); } @@ -149,7 +149,7 @@ static void shrink_histfile (void) } cleanup: - fclose (f); + safe_fclose (&f); FREE (&linebuf); if (tmp != NULL) { @@ -158,9 +158,9 @@ cleanup: { rewind (tmp); mutt_copy_stream (tmp, f); - fclose (f); + safe_fclose (&f); } - fclose (tmp); + safe_fclose (&tmp); unlink (tmpfname); } } @@ -196,7 +196,7 @@ static void save_history (history_class_t hclass, const char *s) } fputs ("|\n", f); - fclose (f); + safe_fclose (&f); FREE (&tmp); if (--n < 0) diff --git a/imap/message.c b/imap/message.c index 5bcd6fb7..32d794e6 100644 --- a/imap/message.c +++ b/imap/message.c @@ -220,7 +220,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (h.data) imap_free_header_data ((void**) (void*) &h.data); imap_hcache_close (idata); - fclose (fp); + safe_fclose (&fp); return -1; } } @@ -331,7 +331,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) #if USE_HCACHE imap_hcache_close (idata); #endif - fclose (fp); + safe_fclose (&fp); return -1; } @@ -364,7 +364,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) imap_hcache_close (idata); #endif /* USE_HCACHE */ - fclose(fp); + safe_fclose (&fp); if (ctx->msgcount > oldmsgcount) { @@ -654,7 +654,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) pc = imap_next_word (pc); mutt_error ("%s", pc); mutt_sleep (1); - fclose (fp); + safe_fclose (&fp); goto fail; } @@ -677,7 +677,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) flush_buffer(buf, &len, idata->conn); mutt_socket_write (idata->conn, "\r\n"); - fclose (fp); + safe_fclose (&fp); do rc = imap_cmd_step (idata); diff --git a/init.c b/init.c index 199a7f0b..f66d551b 100644 --- a/init.c +++ b/init.c @@ -254,7 +254,7 @@ int mutt_extract_token (BUFFER *dest, BUFFER *tok, int flags) /* read line */ memset (&expn, 0, sizeof (expn)); expn.data = mutt_read_line (NULL, &expn.dsize, fp, &line); - fclose (fp); + safe_fclose (&fp); mutt_wait_filter (pid); /* if we got output, make a new string consiting of the shell ouptput @@ -2299,7 +2299,7 @@ static int source_rc (const char *rcfile, BUFFER *err) } FREE (&token.data); FREE (&linebuf); - fclose (f); + safe_fclose (&f); if (pid != -1) mutt_wait_filter (pid); if (rc) diff --git a/lib.c b/lib.c index 146f363f..ed5daed2 100644 --- a/lib.c +++ b/lib.c @@ -220,11 +220,10 @@ int safe_fsync_close (FILE **f) if (fflush (*f) || fsync (fileno (*f))) { r = -1; - fclose (*f); + safe_fclose (f); } else - r = fclose(*f); - *f = NULL; + r = safe_fclose (f); } return r; @@ -345,7 +344,7 @@ void mutt_unlink (const char *s) fwrite (buf, 1, MIN (sizeof (buf), sb.st_size), f); sb.st_size -= MIN (sizeof (buf), sb.st_size); } - fclose (f); + safe_fclose (&f); } } } diff --git a/main.c b/main.c index b984d704..d4023ed3 100644 --- a/main.c +++ b/main.c @@ -909,7 +909,7 @@ int main (int argc, char **argv) if (!option (OPTNOCURSES)) mutt_endwin (NULL); perror (tempfile); - fclose (fin); + safe_fclose (&fin); FREE (&tempfile); exit (1); } @@ -917,9 +917,9 @@ int main (int argc, char **argv) mutt_copy_stream (fin, fout); else if (bodytext) fputs (bodytext, fout); - fclose (fout); + safe_fclose (&fout); if (fin && fin != stdin) - fclose (fin); + safe_fclose (&fin); } } diff --git a/mbox.c b/mbox.c index ec3a02ff..844da877 100644 --- a/mbox.c +++ b/mbox.c @@ -877,7 +877,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) if (fclose (fp) != 0) { fp = NULL; - dprint(1, (debugfile, "mbox_sync_mailbox: fclose() returned non-zero.\n")); + dprint(1, (debugfile, "mbox_sync_mailbox: safe_fclose (&) returned non-zero.\n")); unlink (tempfile); mutt_perror (tempfile); mutt_sleep (5); @@ -939,7 +939,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) } } - fclose (fp); + safe_fclose (&fp); fp = NULL; mbox_unlock_mailbox (ctx); diff --git a/mh.c b/mh.c index e795a02f..e2c5b695 100644 --- a/mh.c +++ b/mh.c @@ -637,7 +637,7 @@ static HEADER *maildir_parse_message (int magic, const char *fname, h->env = mutt_read_rfc822_header (f, h, 0, 0); fstat (fileno (f), &st); - fclose (f); + safe_fclose (&f); if (!h->received) h->received = h->date_sent; diff --git a/mutt_ssl.c b/mutt_ssl.c index 7cf5371d..04e9a44c 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -587,7 +587,7 @@ static int check_certificate_by_digest (X509 *peercert) if (!X509_digest (peercert, EVP_sha1(), peermd, &peermdlen)) { - fclose (fp); + safe_fclose (&fp); return 0; } @@ -599,7 +599,7 @@ static int check_certificate_by_digest (X509 *peercert) break; } X509_free (cert); - fclose (fp); + safe_fclose (&fp); return pass; } @@ -925,7 +925,7 @@ static int interactive_check_cert (X509 *cert, int idx, int len) { if (PEM_write_X509 (fp, cert)) done = 1; - fclose (fp); + safe_fclose (&fp); } if (!done) { diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index 958d0544..0895b66d 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -417,7 +417,7 @@ static int tls_compare_certificates (const gnutls_datum *peercert) } b64_data.size = fread(b64_data.data, 1, b64_data.size, fd1); - fclose(fd1); + safe_fclose (&fd1); do { ret = gnutls_pem_base64_decode_alloc(NULL, &b64_data, &cert); @@ -526,7 +526,7 @@ static int tls_check_stored_hostname (const gnutls_datum *cert, { regfree(&preg); FREE(&linestr); - fclose(fp); + safe_fclose (&fp); return 1; } } @@ -534,7 +534,7 @@ static int tls_check_stored_hostname (const gnutls_datum *cert, } regfree(&preg); - fclose(fp); + safe_fclose (&fp); } /* not found a matching name */ @@ -877,7 +877,7 @@ static int tls_check_one_certificate (const gnutls_datum_t *certdata, gnutls_free (pemdata.data); } } - fclose (fp); + safe_fclose (&fp); } if (!done) { diff --git a/muttlib.c b/muttlib.c index d1ce40c0..f8f99bec 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1093,7 +1093,7 @@ void mutt_FormatString (char *dest, /* output buffer */ if ((pid = mutt_create_filter(command->data, NULL, &filter, NULL))) { n = fread(dest, 1, destlen /* already decremented */, filter); - fclose(filter); + safe_fclose (&filter); dest[n] = '\0'; while (dest[n-1] == '\n' || dest[n-1] == '\r') dest[--n] = '\0'; diff --git a/pager.c b/pager.c index 8f8a92b5..38f2e9e5 100644 --- a/pager.c +++ b/pager.c @@ -1542,7 +1542,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) if (stat (fname, &sb) != 0) { mutt_perror (fname); - fclose (fp); + safe_fclose (&fp); return (-1); } unlink (fname); @@ -2677,7 +2677,7 @@ search_next: } } - fclose (fp); + safe_fclose (&fp); if (IsHeader (extra)) { Context->msgnotreadyet = -1; diff --git a/pattern.c b/pattern.c index b092de86..e693c02f 100644 --- a/pattern.c +++ b/pattern.c @@ -182,7 +182,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) mx_close_message (&msg); if (s.fpout) { - fclose (s.fpout); + safe_fclose (&s.fpout); unlink (tempfile); } return (0); @@ -242,7 +242,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) if (option (OPTTHOROUGHSRC)) { - fclose (fp); + safe_fclose (&fp); unlink (tempfile); } } diff --git a/pgp.c b/pgp.c index 32018e97..8835d9ae 100644 --- a/pgp.c +++ b/pgp.c @@ -605,7 +605,7 @@ int pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) fseeko (s->fpin, sigbdy->offset, 0); mutt_copy_bytes (s->fpin, fp, sigbdy->length); - fclose (fp); + safe_fclose (&fp); mutt_mktemp(pgperrfile); if(!(pgperr = safe_fopen(pgperrfile, "w+"))) @@ -685,7 +685,7 @@ void pgp_extract_keys_from_messages (HEADER *h) if (Context->hdrs[Context->v2r[i]]->security & PGPENCRYPT && !pgp_valid_passphrase()) { - fclose (fpout); + safe_fclose (&fpout); goto bailout; } mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], @@ -698,13 +698,13 @@ void pgp_extract_keys_from_messages (HEADER *h) mutt_parse_mime_message (Context, h); if (h->security & PGPENCRYPT && !pgp_valid_passphrase()) { - fclose (fpout); + safe_fclose (&fpout); goto bailout; } mutt_copy_message (fpout, Context, h, M_CM_DECODE|M_CM_CHARCONV, 0); } - fclose (fpout); + safe_fclose (&fpout); mutt_endwin (NULL); pgp_invoke_import (tempfname); mutt_any_key_to_continue (NULL); @@ -736,7 +736,7 @@ static void pgp_extract_keys_from_attachment (FILE *fp, BODY *top) mutt_body_handler (top, &s); - fclose (tempfp); + safe_fclose (&tempfp); pgp_invoke_import (tempfname); mutt_any_key_to_continue (NULL); @@ -791,7 +791,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) if((pgptmp = safe_fopen (pgptmpfile, "w")) == NULL) { mutt_perror (pgptmpfile); - fclose(pgperr); + safe_fclose (&pgperr); return NULL; } @@ -801,12 +801,12 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) fseeko (s->fpin, a->offset, 0); mutt_copy_bytes (s->fpin, pgptmp, a->length); - fclose (pgptmp); + safe_fclose (&pgptmp); if ((thepid = pgp_invoke_decrypt (&pgpin, &pgpout, NULL, -1, -1, fileno (pgperr), pgptmpfile)) == -1) { - fclose (pgperr); + safe_fclose (&pgperr); unlink (pgptmpfile); if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: could not create a PGP subprocess! --]\n\n"), s); @@ -819,7 +819,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) if (!pgp_use_gpg_agent()) fputs (PgpPass, pgpin); fputc ('\n', pgpin); - fclose(pgpin); + safe_fclose (&pgpin); /* Read the output from PGP, and make sure to change CRLF to LF, otherwise * read_mime_header has a hard time parsing the message. @@ -832,7 +832,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) fputs (buf, fpout); } - fclose (pgpout); + safe_fclose (&pgpout); rv = mutt_wait_filter (thepid); mutt_unlink(pgptmpfile); @@ -846,7 +846,7 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) p->goodsig = 0; state_attach_puts (_("[-- End of PGP output --]\n\n"), s); } - fclose (pgperr); + safe_fclose (&pgperr); fflush (fpout); rewind (fpout); @@ -985,7 +985,7 @@ int pgp_encrypted_handler (BODY *a, STATE *s) rc = -1; } - fclose (fpout); + safe_fclose (&fpout); mutt_unlink(tempfile); return rc; @@ -1018,7 +1018,7 @@ BODY *pgp_sign_message (BODY *a) if ((sfp = safe_fopen(signedfile, "w")) == NULL) { mutt_perror(signedfile); - fclose(fp); + safe_fclose (&fp); unlink(sigfile); return NULL; } @@ -1026,13 +1026,13 @@ BODY *pgp_sign_message (BODY *a) mutt_write_mime_header (a, sfp); fputc ('\n', sfp); mutt_write_mime_body (a, sfp); - fclose(sfp); + safe_fclose (&sfp); if ((thepid = pgp_invoke_sign (&pgpin, &pgpout, &pgperr, -1, -1, -1, signedfile)) == -1) { mutt_perror _("Can't open PGP subprocess!"); - fclose(fp); + safe_fclose (&fp); unlink(sigfile); unlink(signedfile); return NULL; @@ -1041,7 +1041,7 @@ BODY *pgp_sign_message (BODY *a) if (!pgp_use_gpg_agent()) fputs(PgpPass, pgpin); fputc('\n', pgpin); - fclose(pgpin); + safe_fclose (&pgpin); /* * Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as @@ -1069,8 +1069,8 @@ BODY *pgp_sign_message (BODY *a) if(mutt_wait_filter (thepid) && option(OPTPGPCHECKEXIT)) empty=1; - fclose (pgperr); - fclose (pgpout); + safe_fclose (&pgperr); + safe_fclose (&pgpout); unlink (signedfile); if (fclose (fp) != 0) @@ -1268,7 +1268,7 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) { mutt_perror (pgperrfile); unlink(tempfile); - fclose(fpout); + safe_fclose (&fpout); return NULL; } unlink (pgperrfile); @@ -1278,8 +1278,8 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) { mutt_perror(pgpinfile); unlink(tempfile); - fclose(fpout); - fclose(pgperr); + safe_fclose (&fpout); + safe_fclose (&pgperr); return NULL; } @@ -1289,13 +1289,13 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - fclose(fptmp); + safe_fclose (&fptmp); if ((thepid = pgp_invoke_encrypt (&pgpin, NULL, NULL, -1, fileno (fpout), fileno (pgperr), pgpinfile, keylist, sign)) == -1) { - fclose (pgperr); + safe_fclose (&pgperr); unlink(pgpinfile); return (NULL); } @@ -1306,7 +1306,7 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) fputs (PgpPass, pgpin); fputc ('\n', pgpin); } - fclose(pgpin); + safe_fclose (&pgpin); if(mutt_wait_filter (thepid) && option(OPTPGPCHECKEXIT)) empty=1; @@ -1317,7 +1317,7 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) rewind (fpout); if(!empty) empty = (fgetc (fpout) == EOF); - fclose (fpout); + safe_fclose (&fpout); fflush (pgperr); rewind (pgperr); @@ -1326,7 +1326,7 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) err = 1; fputs (buf, stdout); } - fclose (pgperr); + safe_fclose (&pgperr); /* pause if there is any error output from PGP */ if (err) @@ -1406,7 +1406,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) if ((pgpin = safe_fopen (pgpinfile, "w")) == NULL) { mutt_perror (pgpinfile); - fclose (fp); + safe_fclose (&fp); return NULL; } @@ -1445,7 +1445,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) mutt_copy_stream (fp, pgpin); } safe_fclose (&fp); - fclose (pgpin); + safe_fclose (&pgpin); mutt_mktemp (pgpoutfile); mutt_mktemp (pgperrfile); @@ -1456,7 +1456,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) unlink (pgpinfile); if (pgpout) { - fclose (pgpout); + safe_fclose (&pgpout); unlink (pgpoutfile); } return NULL; @@ -1469,8 +1469,8 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) pgpinfile, keylist, flags)) == -1) { mutt_perror _("Can't invoke PGP"); - fclose (pgpout); - fclose (pgperr); + safe_fclose (&pgpout); + safe_fclose (&pgperr); mutt_unlink (pgpinfile); unlink (pgpoutfile); return NULL; @@ -1480,7 +1480,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) *PgpPass = 0; if (flags & SIGN) fprintf (pgpin, "%s\n", PgpPass); - fclose (pgpin); + safe_fclose (&pgpin); if(mutt_wait_filter (thepid) && option(OPTPGPCHECKEXIT)) empty=1; @@ -1495,7 +1495,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) if(!empty) empty = (fgetc (pgpout) == EOF); - fclose (pgpout); + safe_fclose (&pgpout); err = 0; @@ -1505,7 +1505,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) fputs (buff, stdout); } - fclose (pgperr); + safe_fclose (&pgperr); if (err) mutt_any_key_to_continue (NULL); diff --git a/pgpkey.c b/pgpkey.c index 3d81932b..9f04df30 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -555,7 +555,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, } if ((fp = safe_fopen (tempfile, "w")) == NULL) { - fclose (devnull); + safe_fclose (&devnull); mutt_perror _("Can't create temporary file"); break; } @@ -569,13 +569,13 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, { mutt_perror _("Can't create filter"); unlink (tempfile); - fclose (fp); - fclose (devnull); + safe_fclose (&fp); + safe_fclose (&devnull); } mutt_wait_filter (thepid); - fclose (fp); - fclose (devnull); + safe_fclose (&fp); + safe_fclose (&devnull); mutt_clear_error (); snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), pgp_keyid (pgp_principal_key (KeyTable[menu->current]->parent))); @@ -743,7 +743,7 @@ BODY *pgp_make_key_attachment (char *tempf) if ((devnull = fopen ("/dev/null", "w")) == NULL) /* __FOPEN_CHECKED__ */ { mutt_perror _("Can't open /dev/null"); - fclose (tempfp); + safe_fclose (&tempfp); if (tempf == tempfb) unlink (tempf); return NULL; @@ -758,15 +758,15 @@ BODY *pgp_make_key_attachment (char *tempf) { mutt_perror _("Can't create filter"); unlink (tempf); - fclose (tempfp); - fclose (devnull); + safe_fclose (&tempfp); + safe_fclose (&devnull); return NULL; } mutt_wait_filter (thepid); - fclose (tempfp); - fclose (devnull); + safe_fclose (&tempfp); + safe_fclose (&devnull); att = mutt_new_body (); att->filename = safe_strdup (tempf); diff --git a/pgppubring.c b/pgppubring.c index 358e3b7d..b85dca0e 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -815,7 +815,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[], int nh FGETPOS(rfp,pos); } - fclose (rfp); + safe_fclose (&rfp); } diff --git a/pop.c b/pop.c index 34a0f63d..67406453 100644 --- a/pop.c +++ b/pop.c @@ -130,7 +130,7 @@ static int pop_read_header (POP_DATA *pop_data, HEADER *h) } } - fclose (f); + safe_fclose (&f); unlink (tempfile); return ret; } diff --git a/postpone.c b/postpone.c index 12bc7cc5..dae69644 100644 --- a/postpone.c +++ b/postpone.c @@ -705,7 +705,7 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr, bail: /* that's it. */ - if (bfp != fp) fclose (bfp); + if (bfp != fp) safe_fclose (&bfp); if (msg) mx_close_message (&msg); if (rv == -1) diff --git a/query.c b/query.c index 7006aa6a..19dbc19a 100644 --- a/query.c +++ b/query.c @@ -123,7 +123,7 @@ static QUERY *run_query (char *s, int quiet) } } FREE (&buf); - fclose (fp); + safe_fclose (&fp); if (mutt_wait_filter (thepid)) { dprint (1, (debugfile, "Error: %s\n", msg)); diff --git a/recvattach.c b/recvattach.c index 86448ff7..04ab50c2 100644 --- a/recvattach.c +++ b/recvattach.c @@ -518,7 +518,7 @@ void mutt_save_attachment_list (FILE *fp, int tag, BODY *top, HEADER *hdr, MUTTM if (rc == 0 && AttachSep && (fpout = fopen (tfile,"a")) != NULL) { fprintf(fpout, "%s", AttachSep); - fclose (fpout); + safe_fclose (&fpout); } } else @@ -527,7 +527,7 @@ void mutt_save_attachment_list (FILE *fp, int tag, BODY *top, HEADER *hdr, MUTTM if (rc == 0 && AttachSep && (fpout = fopen (tfile,"a")) != NULL) { fprintf(fpout, "%s", AttachSep); - fclose (fpout); + safe_fclose (&fpout); } } } @@ -622,7 +622,7 @@ static void pipe_attachment (FILE *fp, BODY *b, STATE *state) return; } mutt_copy_stream (ifp, state->fpout); - fclose (ifp); + safe_fclose (&ifp); if (AttachSep) state_puts (AttachSep, state); } @@ -671,7 +671,7 @@ void mutt_pipe_attachment_list (FILE *fp, int tag, BODY *top, int filter) mutt_endwin (NULL); thepid = mutt_create_filter (buf, &state.fpout, NULL, NULL); pipe_attachment_list (buf, fp, tag, top, filter, &state); - fclose (state.fpout); + safe_fclose (&state.fpout); if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY)) mutt_any_key_to_continue (NULL); } @@ -737,7 +737,7 @@ static void print_attachment_list (FILE *fp, int tag, BODY *top, STATE *state) if ((ifp = fopen (newfile, "r")) != NULL) { mutt_copy_stream (ifp, state->fpout); - fclose (ifp); + safe_fclose (&ifp); if (AttachSep) state_puts (AttachSep, state); } @@ -771,7 +771,7 @@ void mutt_print_attachment_list (FILE *fp, int tag, BODY *top) memset (&state, 0, sizeof (STATE)); thepid = mutt_create_filter (NONULL (PrintCmd), &state.fpout, NULL, NULL); print_attachment_list (fp, tag, top, &state); - fclose (state.fpout); + safe_fclose (&state.fpout); if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY)) mutt_any_key_to_continue (NULL); } @@ -1242,7 +1242,7 @@ void mutt_view_attachments (HEADER *hdr) if (WithCrypto && need_secured && secured) { - fclose (fp); + safe_fclose (&fp); mutt_free_body (&cur); } diff --git a/recvcmd.c b/recvcmd.c index 26312d69..05829a47 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -515,7 +515,7 @@ _("Can't decode all tagged attachments. MIME-forward the others?"))) == -1) mutt_forward_trailer (tmpfp); - fclose (tmpfp); + safe_fclose (&tmpfp); tmpfp = NULL; /* now that we have the template, send it. */ @@ -526,7 +526,7 @@ _("Can't decode all tagged attachments. MIME-forward the others?"))) == -1) if (tmpfp) { - fclose (tmpfp); + safe_fclose (&tmpfp); mutt_unlink (tmpbody); } @@ -631,7 +631,7 @@ static void attach_forward_msgs (FILE * fp, HEADER * hdr, } } } - fclose (tmpfp); + safe_fclose (&tmpfp); } else if (rc == M_YES) /* do MIME encapsulation - we don't need to do much here */ { @@ -907,12 +907,12 @@ void mutt_attach_reply (FILE * fp, HEADER * hdr, copy_problematic_attachments (fp, &tmphdr->content, idx, idxlen, 0) == NULL) { mutt_free_header (&tmphdr); - fclose (tmpfp); + safe_fclose (&tmpfp); return; } } - fclose (tmpfp); + safe_fclose (&tmpfp); if (ci_send_message (flags, tmphdr, tmpbody, NULL, parent) == 0) mutt_set_flag (Context, hdr, M_REPLIED, 1); diff --git a/rfc1524.c b/rfc1524.c index e04a9b06..52878708 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -346,7 +346,7 @@ static int rfc1524_mailcap_parse (BODY *a, } } } /* while (!found && (buf = mutt_read_line ())) */ - fclose (fp); + safe_fclose (&fp); } /* if ((fp = fopen ())) */ FREE (&buf); return found; @@ -581,12 +581,12 @@ int mutt_rename_file (char *oldfile, char *newfile) return 3; if ((nfp = safe_fopen (newfile,"w")) == NULL) { - fclose(ofp); + safe_fclose (&ofp); return 3; } mutt_copy_stream (ofp,nfp); - fclose (nfp); - fclose (ofp); + safe_fclose (&nfp); + safe_fclose (&ofp); mutt_unlink (oldfile); return 0; } diff --git a/rfc3676.c b/rfc3676.c index 4de8ba7c..8bcef2bc 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -270,7 +270,7 @@ void rfc3676_space_stuff (HEADER* hdr) mutt_mktemp (tmpfile); if ((out = safe_fopen (tmpfile, "w+")) == NULL) { - fclose (in); + safe_fclose (&in); return; } @@ -294,8 +294,8 @@ void rfc3676_space_stuff (HEADER* hdr) } fputs (buf, out); } - fclose (in); - fclose (out); + safe_fclose (&in); + safe_fclose (&out); mutt_set_mtime (hdr->content->filename, tmpfile); unlink (hdr->content->filename); mutt_str_replace (&hdr->content->filename, tmpfile); diff --git a/send.c b/send.c index 8b47f2c6..6bd61487 100644 --- a/send.c +++ b/send.c @@ -59,7 +59,7 @@ static void append_signature (FILE *f) if (option (OPTSIGDASHES)) fputs ("\n-- \n", f); mutt_copy_stream (tmpfp, f); - fclose (tmpfp); + safe_fclose (&tmpfp); if (thepid != -1) mutt_wait_filter (thepid); } @@ -997,7 +997,7 @@ static int send_message (HEADER *msg) if ((mutt_write_mime_body (msg->content, tempfp) == -1)) { - fclose(tempfp); + safe_fclose (&tempfp); unlink (tempfile); return (-1); } diff --git a/sendlib.c b/sendlib.c index c56b64be..1c9c352d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -458,7 +458,7 @@ int mutt_write_mime_body (BODY *a, FILE *f) mutt_copy_stream (fpin, f); fgetconv_close (&fc); - fclose (fpin); + safe_fclose (&fpin); return (ferror (f) ? -1 : 0); } @@ -1004,7 +1004,7 @@ int mutt_lookup_mime_type (BODY *att, const char *path) p = NULL; } } - fclose (f); + safe_fclose (&f); } } @@ -1041,7 +1041,7 @@ void mutt_message_to_7bit (BODY *a, FILE *fp) if (stat (a->filename, &sb) == -1) { mutt_perror ("stat"); - fclose (fpin); + safe_fclose (&fpin); } a->length = sb.st_size; } @@ -1070,9 +1070,9 @@ void mutt_message_to_7bit (BODY *a, FILE *fp) FREE (&line); if (fpin && !fp) - fclose (fpin); + safe_fclose (&fpin); if (fpout) - fclose (fpout); + safe_fclose (&fpout); else return; @@ -1125,7 +1125,7 @@ static void transform_to_7bit (BODY *a, FILE *fpin) } s.fpin = fpin; mutt_decode_attachment (a, &s); - fclose (s.fpout); + safe_fclose (&s.fpout); a->d_filename = a->filename; a->filename = safe_strdup (buff); a->unlink = 1; @@ -1328,7 +1328,7 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) mutt_update_encoding (body); body->parts = body->hdr->content; - fclose(fp); + safe_fclose (&fp); return (body); } @@ -2604,7 +2604,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, if (ferror (tempfp)) { dprint (1, (debugfile, "mutt_write_fcc(): %s: write failed.\n", tempfile)); - fclose (tempfp); + safe_fclose (&tempfp); unlink (tempfile); mx_commit_message (msg, &f); /* XXX - really? */ mx_close_message (&msg); diff --git a/smime.c b/smime.c index cda57b0e..95facec1 100644 --- a/smime.c +++ b/smime.c @@ -381,7 +381,7 @@ char* smime_ask_for_key (char *prompt, char *mailbox, short public) while (!feof(index)) { if (fgets(buf, sizeof(buf), index)) cert_num++; } - fclose(index); + safe_fclose (&index); FOREVER { @@ -425,7 +425,7 @@ char* smime_ask_for_key (char *prompt, char *mailbox, short public) cur++; } - fclose(index); + safe_fclose (&index); /* Make Helpstring */ helpstr[0] = 0; @@ -836,7 +836,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, mutt_mktemp (tmpfname); if ((fpout = safe_fopen (tmpfname, "w+")) == NULL) { - fclose (fperr); + safe_fclose (&fperr); mutt_perror (tmpfname); return 1; } @@ -848,8 +848,8 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, SmimeGetCertEmailCommand))== -1) { mutt_message (_("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + safe_fclose (&fperr); + safe_fclose (&fpout); return 1; } @@ -899,8 +899,8 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, } else if(copy) ret = 2; - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); return ret; } @@ -927,7 +927,7 @@ static char *smime_extract_certificate (char *infile) mutt_mktemp (pk7out); if ((fpout = safe_fopen (pk7out, "w+")) == NULL) { - fclose (fperr); + safe_fclose (&fperr); mutt_perror (pk7out); return NULL; } @@ -941,8 +941,8 @@ static char *smime_extract_certificate (char *infile) SmimePk7outCommand))== -1) { mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + safe_fclose (&fperr); + safe_fclose (&fpout); mutt_unlink (pk7out); return NULL; } @@ -959,19 +959,19 @@ static char *smime_extract_certificate (char *infile) { mutt_perror (pk7out); mutt_copy_stream (fperr, stdout); - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); mutt_unlink (pk7out); return NULL; } - fclose (fpout); + safe_fclose (&fpout); mutt_mktemp (certfile); if ((fpout = safe_fopen (certfile, "w+")) == NULL) { - fclose (fperr); + safe_fclose (&fperr); mutt_unlink (pk7out); mutt_perror (certfile); return NULL; @@ -985,8 +985,8 @@ static char *smime_extract_certificate (char *infile) SmimeGetCertCommand))== -1) { mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + safe_fclose (&fperr); + safe_fclose (&fpout); mutt_unlink (pk7out); mutt_unlink (certfile); return NULL; @@ -1004,14 +1004,14 @@ static char *smime_extract_certificate (char *infile) if (empty) { mutt_copy_stream (fperr, stdout); - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); mutt_unlink (certfile); return NULL; } - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); return safe_strdup (certfile); } @@ -1037,7 +1037,7 @@ static char *smime_extract_signer_certificate (char *infile) mutt_mktemp (certfile); if ((fpout = safe_fopen (certfile, "w+")) == NULL) { - fclose (fperr); + safe_fclose (&fperr); mutt_perror (certfile); return NULL; } @@ -1050,8 +1050,8 @@ static char *smime_extract_signer_certificate (char *infile) SmimeGetSignerCertCommand))== -1) { mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!")); - fclose (fperr); - fclose (fpout); + safe_fclose (&fperr); + safe_fclose (&fpout); mutt_unlink (pk7out); mutt_unlink (certfile); return NULL; @@ -1069,14 +1069,14 @@ static char *smime_extract_signer_certificate (char *infile) mutt_endwin (NULL); mutt_copy_stream (fperr, stdout); mutt_any_key_to_continue (NULL); - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); mutt_unlink (certfile); return NULL; } - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); return safe_strdup (certfile); } @@ -1103,7 +1103,7 @@ void smime_invoke_import (char *infile, char *mailbox) mutt_mktemp (tmpfname); if ((fpout = safe_fopen (tmpfname, "w+")) == NULL) { - fclose (fperr); + safe_fclose (&fperr); mutt_perror (tmpfname); return; } @@ -1129,7 +1129,7 @@ void smime_invoke_import (char *infile, char *mailbox) } fputs (buf, smimein); fputc ('\n', smimein); - fclose(smimein); + safe_fclose (&smimein); mutt_wait_filter (thepid); @@ -1145,8 +1145,8 @@ void smime_invoke_import (char *infile, char *mailbox) mutt_copy_stream (fpout, stdout); mutt_copy_stream (fperr, stdout); - fclose (fpout); - fclose (fperr); + safe_fclose (&fpout); + safe_fclose (&fperr); } @@ -1173,7 +1173,7 @@ int smime_verify_sender(HEADER *h) mutt_copy_message (fpout, Context, h, 0, 0); fflush(fpout); - fclose (fpout); + safe_fclose (&fpout); if (h->env->from) { @@ -1274,7 +1274,7 @@ BODY *smime_build_smime_entity (BODY *a, char *certlist) if ((smimeerr = safe_fopen (smimeerrfile, "w+")) == NULL) { mutt_perror (smimeerrfile); - fclose (fpout); + safe_fclose (&fpout); mutt_unlink (tempfile); return NULL; } @@ -1285,8 +1285,8 @@ BODY *smime_build_smime_entity (BODY *a, char *certlist) { mutt_perror (smimeinfile); mutt_unlink (tempfile); - fclose (fpout); - fclose (smimeerr); + safe_fclose (&fpout); + safe_fclose (&smimeerr); return NULL; } @@ -1308,20 +1308,20 @@ BODY *smime_build_smime_entity (BODY *a, char *certlist) mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - fclose (fptmp); + safe_fclose (&fptmp); if ((thepid = smime_invoke_encrypt (&smimein, NULL, NULL, -1, fileno (fpout), fileno (smimeerr), smimeinfile, certfile)) == -1) { - fclose (smimeerr); + safe_fclose (&smimeerr); mutt_unlink (smimeinfile); mutt_unlink (certfile); return (NULL); } - fclose (smimein); + safe_fclose (&smimein); mutt_wait_filter (thepid); mutt_unlink (smimeinfile); @@ -1330,7 +1330,7 @@ BODY *smime_build_smime_entity (BODY *a, char *certlist) fflush (fpout); rewind (fpout); empty = (fgetc (fpout) == EOF); - fclose (fpout); + safe_fclose (&fpout); fflush (smimeerr); rewind (smimeerr); @@ -1339,7 +1339,7 @@ BODY *smime_build_smime_entity (BODY *a, char *certlist) err = 1; fputs (buf, stdout); } - fclose (smimeerr); + safe_fclose (&smimeerr); /* pause if there is any error output from SMIME */ if (err) @@ -1409,7 +1409,7 @@ BODY *smime_sign_message (BODY *a ) if ((smimeout = safe_fopen (signedfile, "w+")) == NULL) { mutt_perror (signedfile); - fclose (sfp); + safe_fclose (&sfp); mutt_unlink (filetosign); return NULL; } @@ -1417,7 +1417,7 @@ BODY *smime_sign_message (BODY *a ) mutt_write_mime_header (a, sfp); fputc ('\n', sfp); mutt_write_mime_body (a, sfp); - fclose (sfp); + safe_fclose (&sfp); @@ -1436,14 +1436,14 @@ BODY *smime_sign_message (BODY *a ) -1, fileno (smimeout), -1, filetosign)) == -1) { mutt_perror _("Can't open OpenSSL subprocess!"); - fclose (smimeout); + safe_fclose (&smimeout); mutt_unlink (signedfile); mutt_unlink (filetosign); return NULL; } fputs (SmimePass, smimein); fputc ('\n', smimein); - fclose (smimein); + safe_fclose (&smimein); mutt_wait_filter (thepid); @@ -1457,13 +1457,13 @@ BODY *smime_sign_message (BODY *a ) err = 1; fputs (buffer, stdout); } - fclose (smimeerr); + safe_fclose (&smimeerr); fflush (smimeout); rewind (smimeout); empty = (fgetc (smimeout) == EOF); - fclose (smimeout); + safe_fclose (&smimeout); mutt_unlink (filetosign); @@ -1584,7 +1584,7 @@ int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) sigbdy->length = ftello (s->fpout); sigbdy->offset = 0; - fclose (s->fpout); + safe_fclose (&s->fpout); /* restore final destination and substitute the tempfile for input */ s->fpout = fp; @@ -1612,7 +1612,7 @@ int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) tempfile, signedfile, 0)) != -1) { fflush (smimeout); - fclose (smimeout); + safe_fclose (&smimeout); if (mutt_wait_filter (thepid)) badsig = -1; @@ -1636,7 +1636,7 @@ int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) fflush (smimeerr); rewind (smimeerr); mutt_copy_stream (smimeerr, s->fpout); - fclose (smimeerr); + safe_fclose (&smimeerr); state_attach_puts (_("[-- End of OpenSSL output --]\n\n"), s); @@ -1647,7 +1647,7 @@ int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) sigbdy->offset = tmpoffset; /* restore the original source stream */ - fclose (s->fpin); + safe_fclose (&s->fpin); s->fpin = fp; @@ -1692,7 +1692,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) if ((smimeerr = safe_fopen (errfile, "w+")) == NULL) { mutt_perror (errfile); - fclose (smimeout); smimeout = NULL; + safe_fclose (&smimeout); smimeout = NULL; return NULL; } mutt_unlink (errfile); @@ -1702,8 +1702,8 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL) { mutt_perror (tmpfname); - fclose (smimeout); smimeout = NULL; - fclose (smimeerr); smimeerr = NULL; + safe_fclose (&smimeout); smimeout = NULL; + safe_fclose (&smimeerr); smimeerr = NULL; return NULL; } @@ -1713,13 +1713,13 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) mutt_copy_bytes (s->fpin, tmpfp, m->length); fflush (tmpfp); - fclose (tmpfp); + safe_fclose (&tmpfp); if ((type & ENCRYPT) && (thepid = smime_invoke_decrypt (&smimein, NULL, NULL, -1, fileno (smimeout), fileno (smimeerr), tmpfname)) == -1) { - fclose (smimeout); smimeout = NULL; + safe_fclose (&smimeout); smimeout = NULL; mutt_unlink (tmpfname); if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); @@ -1730,7 +1730,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) fileno (smimeout), fileno (smimeerr), NULL, tmpfname, SIGNOPAQUE)) == -1) { - fclose (smimeout); smimeout = NULL; + safe_fclose (&smimeout); smimeout = NULL; mutt_unlink (tmpfname); if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); @@ -1746,7 +1746,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) fputc ('\n', smimein); } - fclose (smimein); + safe_fclose (&smimein); mutt_wait_filter (thepid); mutt_unlink (tmpfname); @@ -1785,7 +1785,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) if ((fpout = safe_fopen (tmptmpfname, "w+")) == NULL) { mutt_perror(tmptmpfname); - fclose (smimeout); smimeout = NULL; + safe_fclose (&smimeout); smimeout = NULL; return NULL; } } @@ -1819,13 +1819,13 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) } } - fclose (smimeout); + safe_fclose (&smimeout); smimeout = NULL; mutt_unlink (outfile); if (!outFile) { - fclose (fpout); + safe_fclose (&fpout); mutt_unlink (tmptmpfname); } fpout = NULL; @@ -1857,7 +1857,7 @@ static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile) m->goodsig = p->goodsig; m->badsig = p->badsig; } - fclose (smimeerr); + safe_fclose (&smimeerr); return (p); } diff --git a/smtp.c b/smtp.c index a49d25cb..e6c82f90 100644 --- a/smtp.c +++ b/smtp.c @@ -164,12 +164,12 @@ smtp_data (CONNECTION * conn, const char *msgfile) snprintf (buf, sizeof (buf), "DATA\r\n"); if (mutt_socket_write (conn, buf) == -1) { - fclose (fp); + safe_fclose (&fp); return smtp_err_write; } if ((r = smtp_get_resp (conn))) { - fclose (fp); + safe_fclose (&fp); return r; } @@ -183,19 +183,19 @@ smtp_data (CONNECTION * conn, const char *msgfile) { if (mutt_socket_write_d (conn, ".", -1, M_SOCK_LOG_FULL) == -1) { - fclose (fp); + safe_fclose (&fp); return smtp_err_write; } } if (mutt_socket_write_d (conn, buf, -1, M_SOCK_LOG_FULL) == -1) { - fclose (fp); + safe_fclose (&fp); return smtp_err_write; } mutt_progress_update (&progress, ftell (fp), -1); } - fclose (fp); + safe_fclose (&fp); /* terminate the message body */ if (mutt_socket_write (conn, ".\r\n") == -1)