Brendan Cully avatar Brendan Cully committed 4cd2daa

openssl: only call SSL_shutdown during clean shutdown (closes #3407)

Comments (0)

Files changed (2)

-2010-03-22 20:02 -0700  marcel  <marcel@telka.sk>  (f544730656c1)
+2010-04-22 09:14 -0700  Vincent Lefevre  <vincent@vinc17.net>  (6ebdfd09abc1)
+
+	* po/fr.po: updated French translation
+
+2010-04-14 15:47 -0700  Michael Elkins  <me@mutt.org>  (15b9d6f3284f)
+
+	* pgp.c: remove toggle and replace with format in pgp-menu
+
+2010-04-12 15:13 -0500  David Champion  <dgc@uchicago.edu>  (41a46373ddd9)
+
+	* compose.c: Improve clarity/uniformity in compose menu's crypto
+	display
+
+	Incorporates feedback on "Security: None" key hints.
+
+2010-04-13 06:49 -0700  Michael Elkins  <me@mutt.org>  (4d798ee2898e)
+
+	* muttlib.c: fix bug handling wide pad char in soft-fill mode
+
+2010-04-11 20:00 -0700  Michael Elkins  <me@mutt.org>  (2cd62f40d840)
+
+	* compose.c: increase size of buffer used for displaying addresses in
+	the compose menu to avoid truncating on widescreen displays
+
+	* curs_lib.c: clear prompt when user cancels with ^G from a yes/no
+	prompt
+
+	* muttlib.c: Fix bug in soft-fill (%*) in $index_format not accounting
+	for 'set arrow_cursor'
+
+	* pgp.c: Remove the (i) option from the PGP-menu when encryption or
+	signing is not yet selected. The toggle between PGP/MIME and
+	Traditional doesn't make sense unless some type of security has been
+	requested.
+
+	Closes #3402.
+
+2010-04-06 09:47 -0700  Michael Elkins  <me@mutt.org>  (889aa698cc49)
+
+	* configure.ac, muttlib.c: fix for compiling Mutt with clang: check
+	for wchar_h prior to wctype_h in check for wc funcs
+
+2010-04-05 11:12 -0700  Michael Elkins  <me@mutt.org>  (844174efa648)
+
+	* doc/manual.xml.head: [doc] Remove bogus -group parameter from
+	unlists and unsubscribe commands; add links to address group section
+	for context.
+
+2010-04-03 20:34 -0700  Michael Elkins  <me@mutt.org>  (cf97505addf8)
+
+	* init.c: prevent user from setting $charset to an empty string since
+	other code requires it to be set to a valid string
+
+	closes #3326
+
+	* pager.c: allow regexps to match on continuation header lines in
+	'color header' commands.
+
+	closes #3373
+
+	* pattern.c: Fix crash on invalid regexp in search string due to
+	uninitialized BUFFER variable.
+
+	Closes #3401
+
+2010-04-01 10:10 -0700  Simon Ruderich  <simon@ruderich.org>  (b9baa0234846)
+
+	* attach.c, commands.c, filter.c, muttlib.c, send.c: fix comment typos
+
+2010-04-01 09:59 -0700  Michael Elkins  <me@mutt.org>  (96ed7cdacdc6)
+
+	* init.h: Improve documentation for $query_command to note that Mutt
+	automatically adds quotes according to shell quoting rules (thx:
+	Simon Ruderich).
+
+	* doc/manual.xml.head: Clarify the documentation on what the line-
+	editor is (thx: Simon Ruderich)
+
+2010-03-31 08:50 -0700  Michael Elkins  <me@mutt.org>  (7e9e31b1bd7b)
+
+	* muttlib.c: avoid buffer overflow when expanding the format string
+	associated with a 'spam' command.
+
+	closes #3397
+
+2010-03-23 16:03 -0700  Michael Elkins  <me@mutt.org>  (fe29d691deff)
+
+	* doc/muttrc.man.head: remove errant commands in secton on setting
+	alternates
+
+2010-03-22 22:16 -0700  Brendan Cully  <brendan@kublai.com>  (69e9a1a0ba2f)
+
+	* sendlib.c: Fix a format string warning
+
+2010-03-22 20:02 -0700  Marcel Telka  <marcel@telka.sk>  (f544730656c1)
 
 	* compose.c: redraw entire screen when exiting editor after re-editing
 	the message body in the send menu.
  * open up another connection to the same server in this session */
 static STACK_OF(X509) *SslSessionCerts = NULL;
 
-typedef struct _sslsockdata
+typedef struct
 {
   SSL_CTX *ctx;
   SSL *ssl;
   X509 *cert;
+  unsigned char isopen;
 }
 sslsockdata;
 
 static int ssl_socket_open (CONNECTION * conn);
 static int ssl_socket_close (CONNECTION * conn);
 static int tls_close (CONNECTION* conn);
+static void ssl_err (sslsockdata *data, int err);
 static int ssl_cache_trusted_cert (X509 *cert);
 static int ssl_check_certificate (CONNECTION *conn, sslsockdata * data);
 static int interactive_check_cert (X509 *cert, int idx, int len);
   if (ssl_negotiate (conn, ssldata))
     goto bail_ssl;
 
+  ssldata->isopen = 1;
+
   /* hmm. watch out if we're starting TLS over any method other than raw. */
   conn->sockdata = ssldata;
   conn->conn_read = ssl_socket_read;
 static int ssl_socket_read (CONNECTION* conn, char* buf, size_t len)
 {
   sslsockdata *data = conn->sockdata;
-  return SSL_read (data->ssl, buf, len);
+  int rc;
+
+  rc = SSL_read (data->ssl, buf, len);
+  if (rc <= 0)
+  {
+    data->isopen = 0;
+    ssl_err (data, rc);
+  }
+
+  return rc;
 }
 
 static int ssl_socket_write (CONNECTION* conn, const char* buf, size_t len)
 {
   sslsockdata *data = conn->sockdata;
-  return SSL_write (data->ssl, buf, len);
+  int rc;
+
+  rc = SSL_write (data->ssl, buf, len);
+  if (rc <= 0)
+    ssl_err (data, rc);
+
+  return rc;
 }
 
 static int ssl_socket_open (CONNECTION * conn)
     return -1;
   }
 
+  data->isopen = 1;
+
   conn->ssf = SSL_CIPHER_get_bits (SSL_get_current_cipher (data->ssl),
     &maxbits);
 
   sslsockdata *data = conn->sockdata;
   if (data)
   {
-    SSL_shutdown (data->ssl);
+    if (data->isopen)
+      SSL_shutdown (data->ssl);
 
     /* hold onto this for the life of mutt, in case we want to reconnect.
      * The purist in me wants a mutt_exit hook. */
   return rc;
 }
 
+static void ssl_err (sslsockdata *data, int err)
+{
+  const char* errmsg;
+  unsigned long sslerr;
+
+  switch (SSL_get_error (data->ssl, err))
+  {
+  case SSL_ERROR_NONE:
+    return;
+  case SSL_ERROR_ZERO_RETURN:
+    errmsg = "SSL connection closed";
+    data->isopen = 0;
+    break;
+  case SSL_ERROR_WANT_READ:
+    errmsg = "retry read";
+    break;
+  case SSL_ERROR_WANT_WRITE:
+    errmsg = "retry write";
+    break;
+  case SSL_ERROR_WANT_CONNECT:
+    errmsg = "retry connect";
+    break;
+  case SSL_ERROR_WANT_ACCEPT:
+    errmsg = "retry accept";
+    break;
+  case SSL_ERROR_WANT_X509_LOOKUP:
+    errmsg = "retry x509 lookup";
+    break;
+  case SSL_ERROR_SYSCALL:
+    errmsg = "I/O error";
+    data->isopen = 0;
+    break;
+  case SSL_ERROR_SSL:
+    sslerr = ERR_get_error ();
+    switch (sslerr)
+    {
+    case 0:
+      switch (err)
+      {
+      case 0:
+	errmsg = "EOF";
+	break;
+      default:
+	errmsg = strerror(errno);
+      }
+      break;
+    default:
+      errmsg = ERR_error_string (sslerr, NULL);
+    }
+    break;
+  default:
+    errmsg = "unknown error";
+  }
+
+  dprint (1, (debugfile, "SSL error: %s\n", errmsg));
+}
+
 static char *x509_get_part (char *line, const char *ndx)
 {
   static char ret[SHORT_STRING];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.