From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.bugs 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 Organization: =?UTF-8?Q?=D0=A2=D0=B5=D0=BE=D0=B4=D0=BE=D1=80_?= =?UTF-8?Q?=D0=97=D0=BB=D0=B0=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= @ Cienfuegos Message-ID: <87sjgdoi43.fsf@lifelogs.com> References: <87haxk3dce.fsf@lifelogs.com> <87hax6wakn.fsf@lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1333931897 9192 80.91.229.3 (9 Apr 2012 00:38:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 9 Apr 2012 00:38:17 +0000 (UTC) Cc: Lars Magne Ingebrigtsen , 10904@debbugs.gnu.org To: Thomas Fitzsimmons Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 09 02:38:16 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SH2cZ-0005vV-U6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 09 Apr 2012 02:38:16 +0200 Original-Received: from localhost ([::1]:48559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2cZ-0000e8-BX for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Apr 2012 20:38:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2cV-0000e2-Tz for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 20:38:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SH2cU-0004kg-1Z for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 20:38:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SH2cT-0004kc-UA for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 20:38:09 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SH2dJ-0004U7-RX for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 20:39:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ted Zlatanov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Apr 2012 00:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10904-submit@debbugs.gnu.org id=B10904.133393191417202 (code B ref 10904); Mon, 09 Apr 2012 00:39:01 +0000 Original-Received: (at 10904) by debbugs.gnu.org; 9 Apr 2012 00:38:34 +0000 Original-Received: from localhost ([127.0.0.1]:45690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SH2cq-0004TJ-Qa for submit@debbugs.gnu.org; Sun, 08 Apr 2012 20:38:33 -0400 Original-Received: from z.lifelogs.com ([173.255.230.239]:33262) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SH2cl-0004T8-66 for 10904@debbugs.gnu.org; Sun, 08 Apr 2012 20:38:31 -0400 Original-Received: from heechee (c-76-28-40-19.hsd1.vt.comcast.net [76.28.40.19]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: tzz) by z.lifelogs.com (Postfix) with ESMTPSA id 9BEE3205F9; Mon, 9 Apr 2012 00:37:33 +0000 (UTC) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never Gmane-Reply-To-List: yes In-Reply-To: (Thomas Fitzsimmons's message of "Sun, 08 Apr 2012 13:46:56 -0400") User-Agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.95 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:58607 Archived-At: --=-=-= Content-Type: text/plain On Sun, 08 Apr 2012 13:46:56 -0400 Thomas Fitzsimmons 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=gnutls-handshakes.patch === 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 #include +#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 }; --=-=-=--