unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Cc: Lars Magne Ingebrigtsen <larsi@gnus.org>, 10904@debbugs.gnu.org
Subject: bug#10904: 24.0.93; Infinite loop in GnuTLS code during Gnus nnimap-initiated SSL handshake
Date: Sun, 08 Apr 2012 20:37:32 -0400	[thread overview]
Message-ID: <87sjgdoi43.fsf@lifelogs.com> (raw)
In-Reply-To: <m3zkamdskv.fsf@fitzsim.org> (Thomas Fitzsimmons's message of "Sun, 08 Apr 2012 13:46:56 -0400")

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]

On Sun, 08 Apr 2012 13:46:56 -0400 Thomas Fitzsimmons <fitzsim@fitzsim.org> wrote: 

TF> The loop happens when the GnuTLS handshake fails for some reason, within
TF> a network process.  I use the attached patch to limit the number of
TF> iterations.  I'm not familiar enough with the Emacs process code to
TF> suggest a fix though.

Thanks again for the help and provided patch.  I modified it to keep the
number of handshakes tried per connection, not globally.  Please try
it.  I will also propose it on emacs-devel for inclusion in the upcoming
24.1 release.

Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gnutls-handshakes.patch --]
[-- Type: text/x-diff, Size: 2635 bytes --]

=== modified file 'src/gnutls.c'
--- src/gnutls.c	2012-02-13 20:39:46 +0000
+++ src/gnutls.c	2012-04-09 00:34:32 +0000
@@ -259,6 +259,12 @@
   message ("gnutls.c: [%d] %s %s", level, string, extra);
 }
 
+static void
+gnutls_log_function2i (int level, const char* string, int extra)
+{
+  message ("gnutls.c: [%d] %s %d", level, string, extra);
+}
+
 static int
 emacs_gnutls_handshake (struct Lisp_Process *proc)
 {
@@ -399,10 +405,22 @@
   ssize_t rtnval;
   gnutls_session_t state = proc->gnutls_state;
 
+  int log_level = proc->gnutls_log_level;
+
   if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
     {
-      emacs_gnutls_handshake (proc);
-      return -1;
+      if (proc->gnutls_handshakes_tried < GNUTLS_EMACS_HANDSHAKES_LIMIT)
+        {
+          proc->gnutls_handshakes_tried++;
+          emacs_gnutls_handshake (proc);
+          GNUTLS_LOG2i (5, log_level, "Retried handshake", 
+                        proc->gnutls_handshakes_tried);
+          return -1;
+        }
+
+      GNUTLS_LOG (2, log_level, "Giving up on handshake; resetting retries");
+      proc->gnutls_handshakes_tried = 0;
+      return 0;
     }
   rtnval = fn_gnutls_record_recv (state, buf, nbyte);
   if (rtnval >= 0)

=== modified file 'src/gnutls.h'
--- src/gnutls.h	2012-01-05 09:46:05 +0000
+++ src/gnutls.h	2012-04-09 00:29:27 +0000
@@ -23,6 +23,8 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
+#define GNUTLS_EMACS_HANDSHAKES_LIMIT 100
+
 typedef enum
 {
   /* Initialization stages.  */
@@ -53,6 +55,8 @@
 
 #define GNUTLS_LOG2(level, max, string, extra) do { if (level <= max) { gnutls_log_function2 (level, "(Emacs) " string, extra); } } while (0)
 
+#define GNUTLS_LOG2i(level, max, string, extra) do { if (level <= max) { gnutls_log_function2i (level, "(Emacs) " string, extra); } } while (0)
+
 extern EMACS_INT
 emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, EMACS_INT nbyte);
 extern EMACS_INT

=== modified file 'src/process.c'
--- src/process.c	2012-03-23 12:23:14 +0000
+++ src/process.c	2012-04-09 00:24:07 +0000
@@ -641,6 +641,7 @@
 #ifdef HAVE_GNUTLS
   p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
   p->gnutls_log_level = 0;
+  p->gnutls_handshakes_tried = 0;
   p->gnutls_p = 0;
   p->gnutls_state = NULL;
   p->gnutls_x509_cred = NULL;

=== modified file 'src/process.h'
--- src/process.h	2012-01-19 07:21:25 +0000
+++ src/process.h	2012-04-09 00:23:24 +0000
@@ -134,6 +134,7 @@
     gnutls_certificate_client_credentials gnutls_x509_cred;
     gnutls_anon_client_credentials_t gnutls_anon_cred;
     int gnutls_log_level;
+    int gnutls_handshakes_tried;
     int gnutls_p;
 #endif
 };


  reply	other threads:[~2012-04-09  0:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27 23:51 bug#10904: 24.0.93; Infinite loop in GnuTLS code during Gnus nnimap-initiated SSL handshake Thomas Fitzsimmons
2012-03-03 14:56 ` Lars Magne Ingebrigtsen
2012-03-19 13:54   ` Ted Zlatanov
2012-03-21 15:40     ` Thomas Fitzsimmons
2012-03-22 21:29       ` Lars Magne Ingebrigtsen
2012-03-24 22:04         ` Thomas Fitzsimmons
2012-03-30 12:13           ` Ted Zlatanov
2012-03-30 21:52             ` Thomas Fitzsimmons
2012-04-08 17:46               ` Thomas Fitzsimmons
2012-04-09  0:37                 ` Ted Zlatanov [this message]
2012-04-09 13:14                   ` Ted Zlatanov
2012-04-10  3:07                   ` Thomas Fitzsimmons
2012-04-10 11:54                     ` Ted Zlatanov
2012-04-10 17:44                       ` Lars Magne Ingebrigtsen
2012-04-11 12:02                         ` Ted Zlatanov
2014-12-08 20:06                       ` Lars Magne Ingebrigtsen
2014-12-10 16:10                         ` Ted Zlatanov
2016-02-05  7:26                           ` Lars Ingebrigtsen
2016-06-02 14:21                             ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sjgdoi43.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=10904@debbugs.gnu.org \
    --cc=fitzsim@fitzsim.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).