diff options
author | Rocco Rutte <pdmef@gmx.net> | 2009-03-15 13:46:52 +0100 |
---|---|---|
committer | Rocco Rutte <pdmef@gmx.net> | 2009-03-15 13:46:52 +0100 |
commit | 8cfd92192fbe9b2c17fdc2b262592a486025d0ff (patch) | |
tree | 6fa88dcb48254bd3d5a6492eb7889671482592db | |
parent | 06d425398e3ef6fd3b152d95f6def1b4b14ff43e (diff) |
Use safe_fclose() instead of fclose(), add fclose() to check_sec.sh
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | alias.c | 4 | ||||
-rw-r--r-- | attach.c | 14 | ||||
-rw-r--r-- | buffy.c | 2 | ||||
-rwxr-xr-x | check_sec.sh | 1 | ||||
-rw-r--r-- | commands.c | 2 | ||||
-rw-r--r-- | compose.c | 2 | ||||
-rw-r--r-- | copy.c | 4 | ||||
-rw-r--r-- | crypt-gpgme.c | 33 | ||||
-rw-r--r-- | crypt.c | 6 | ||||
-rw-r--r-- | edit.c | 2 | ||||
-rw-r--r-- | editmsg.c | 2 | ||||
-rw-r--r-- | gnupgparse.c | 2 | ||||
-rw-r--r-- | handler.c | 4 | ||||
-rw-r--r-- | headers.c | 10 | ||||
-rw-r--r-- | help.c | 2 | ||||
-rw-r--r-- | history.c | 10 | ||||
-rw-r--r-- | imap/message.c | 10 | ||||
-rw-r--r-- | init.c | 4 | ||||
-rw-r--r-- | lib.c | 7 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | mbox.c | 4 | ||||
-rw-r--r-- | mh.c | 2 | ||||
-rw-r--r-- | mutt_ssl.c | 6 | ||||
-rw-r--r-- | mutt_ssl_gnutls.c | 8 | ||||
-rw-r--r-- | muttlib.c | 2 | ||||
-rw-r--r-- | pager.c | 4 | ||||
-rw-r--r-- | pattern.c | 4 | ||||
-rw-r--r-- | pgp.c | 68 | ||||
-rw-r--r-- | pgpkey.c | 20 | ||||
-rw-r--r-- | pgppubring.c | 2 | ||||
-rw-r--r-- | pop.c | 2 | ||||
-rw-r--r-- | postpone.c | 2 | ||||
-rw-r--r-- | query.c | 2 | ||||
-rw-r--r-- | recvattach.c | 14 | ||||
-rw-r--r-- | recvcmd.c | 10 | ||||
-rw-r--r-- | rfc1524.c | 8 | ||||
-rw-r--r-- | rfc3676.c | 6 | ||||
-rw-r--r-- | send.c | 4 | ||||
-rw-r--r-- | sendlib.c | 16 | ||||
-rw-r--r-- | smime.c | 122 | ||||
-rw-r--r-- | smtp.c | 10 |
42 files changed, 224 insertions, 223 deletions
@@ -1,3 +1,7 @@ +2009-03-10 18:39 +0100 NONAKA Kimihiro <nonakap@gmail.com> (cc6fede605d4) + + * ChangeLog, mh.c: Fix crashes with 64bit time_t. Closes #3184. + 2009-03-09 12:04 +0100 Vincent Lefevre <vincent@vinc17.org> (4ce562b7f5d7) * mbyte.h: Unbreak compilation on OS X with --with-regex/--without-wc- @@ -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; } @@ -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); @@ -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 '\<fopen.*'\"'.*w' __FOPEN_CHECKED__ "Alert: Unchecked fopen calls." +do_check '\<fclose.*'\"'.*w' __FCLOSE_CHECKED__ "Alert: Unchecked fclose calls." do_check '\<(mutt_)?strcpy' __STRCPY_CHECKED__ "Alert: Unchecked strcpy calls." do_check '\<strcat' __STRCAT_CHECKED__ "Alert: Unchecked strcat calls." do_check '\<sprintf.*%s' __SPRINTF_CHECKED__ "Alert: Unchecked sprintf calls." @@ -391,7 +391,7 @@ static int _mutt_pipe_message (HEADER *h, char *cmd, } pipe_msg (h, fpout, decode, print); - fclose (fpout); + safe_fclose (&fpout); rc = mutt_wait_filter (thepid); } else @@ -1073,7 +1073,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ FREE (&idx[idxlen]); continue; } - fclose (fp); + safe_fclose (&fp); if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) { @@ -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); @@ -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); @@ -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 { @@ -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); @@ -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; } } @@ -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. */ @@ -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); } @@ -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); @@ -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) @@ -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); } } } @@ -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); } } @@ -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); @@ -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; @@ -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) { @@ -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'; @@ -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; @@ -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); } } @@ -605,7 +605,7 @@ int pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) fseeko (s->fpin, sigbdy->offset, |