From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thomas Fitzsimmons 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 13:46:56 -0400 Message-ID: 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 1333907242 25336 80.91.229.3 (8 Apr 2012 17:47:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 8 Apr 2012 17:47:22 +0000 (UTC) Cc: Ted Zlatanov , 10904@debbugs.gnu.org To: Lars Magne Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 08 19:47:21 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 1SGwCr-000469-2L for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Apr 2012 19:47:17 +0200 Original-Received: from localhost ([::1]:46433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGwCq-00016Q-FN for geb-bug-gnu-emacs@m.gmane.org; Sun, 08 Apr 2012 13:47:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGwCn-00015v-9X for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 13:47:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SGwCl-0002Go-HF for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 13:47:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGwCl-0002Gk-Dj for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 13:47:11 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SGwDZ-0002bD-Ka for bug-gnu-emacs@gnu.org; Sun, 08 Apr 2012 13:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thomas Fitzsimmons Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Apr 2012 17:48: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.13339072819984 (code B ref 10904); Sun, 08 Apr 2012 17:48:01 +0000 Original-Received: (at 10904) by debbugs.gnu.org; 8 Apr 2012 17:48:01 +0000 Original-Received: from localhost ([127.0.0.1]:44912 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SGwDY-0002ay-ES for submit@debbugs.gnu.org; Sun, 08 Apr 2012 13:48:00 -0400 Original-Received: from mail-iy0-f172.google.com ([209.85.210.172]:60448) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SGwDV-0002ar-Kd for 10904@debbugs.gnu.org; Sun, 08 Apr 2012 13:47:58 -0400 Original-Received: by iazz13 with SMTP id z13so4726120iaz.3 for <10904@debbugs.gnu.org>; Sun, 08 Apr 2012 10:47:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:x-gm-message-state; bh=RtsRXsetgWyUmNFlQO6FGCtw1YC+eXJ0wGnQslbDLDk=; b=EVHwIn56+bdLWAmepRIzdw5Fh5IPBs9vEdPvxJBO9aOb8QrL3vCLoV+1/doo8wN8v4 U6tnIK3h9AWvEf6ZTkCtXZJoFsQ/4idpIBlHJz4+OOoQB0OQWomDcLdCJ7qJxv2rTnOq x22R/1Kkq0HE6337rqBCSN5xefC39BuwTD7HkEI5xGtB+vjWZUqKpnCiqfBDfy9VljVU bmE01b+pMUBw6rCHTrKrFCw4vDi0lRf6VoYv0DBw2NQpMJpR3O7kY16oOO31uZL+5zUB qgxrAWL2aZNEobxh5DXdpK7Hsm+GdbTM9I0FA4jvemK3bJ12uVp8SteED9IJUus1tZ/j 2Xsw== Original-Received: by 10.50.193.234 with SMTP id hr10mr3123610igc.14.1333907226028; Sun, 08 Apr 2012 10:47:06 -0700 (PDT) Original-Received: from ducky.fitzsim.org ([64.231.223.116]) by mx.google.com with ESMTPS id s5sm28792201igb.15.2012.04.08.10.47.04 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 08 Apr 2012 10:47:05 -0700 (PDT) In-Reply-To: (Thomas Fitzsimmons's message of "Fri, 30 Mar 2012 17:52:24 -0400") X-Gm-Message-State: ALoCoQlNmSnJEsYNkjwSzsfI7JqM0xVpxVezSGAf0rsqkDTlV9VEiAwgkG4kxNoYjtc0t8CIGdm5 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:58591 Archived-At: --=-=-= I rechecked this against bzr Emacs and GnuTLS 3.0.17 and it's still there. I tried to create a smaller test case and came up with this: $ gnutls-serv --http & $ emacs -Q (progn (setq gnutls-log-level 5 message-log-max t) (open-protocol-stream "*nnimap*" (current-buffer) "localhost" 5556 :type 'ssl :return-list t :shell-command "ssh %s imapd" :capability-command "1 CAPABILITY\r\n" :end-of-command "\r\n" :success " OK " :starttls-function (lambda (capabilities) (when (gnus-string-match-p "STARTTLS" capabilities) "1 STARTTLS\r\n")))) The open-protocol-stream call is how nnimap-open-connection-1 in lisp/gnus/nnimap.el creates the IMAP network process. The loop happens when the GnuTLS handshake fails for some reason, within a network process. I use the attached patch to limit the number of iterations. I'm not familiar enough with the Emacs process code to suggest a fix though. It would be nice if one of you could try against gnutls-serv and confirm you see this -- I think the problem is general enough that this proves it and will allow a fix that I can test against my IMAP server. However, if need-be I can try to arrange a tunnel to the IMAP server I'm trying to connect to. As for why this hasn't been seen before, it doesn't affect the GnuTLS backend standalone (as Ted pointed out) -- it seems to only happen when an SSL-using process is created and the GnuTLS handshake fails, so it will be rare that it happens. Still, an infinite loop is not a nice failure mode, even if it's rare. Thomas --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=emacs-gnutls-limit-loop.patch --- src/gnutls.c~ 2012-02-13 15:46:01.000000000 -0500 +++ src/gnutls.c 2012-02-23 14:21:22.000000000 -0500 @@ -378,6 +378,8 @@ return (bytes_written); } +static int error_count = 0; + EMACS_INT emacs_gnutls_read (struct Lisp_Process *proc, char *buf, EMACS_INT nbyte) { @@ -386,8 +388,17 @@ if (proc->gnutls_initstage != GNUTLS_STAGE_READY) { + if (error_count < 100) + { + error_count++; emacs_gnutls_handshake (proc); return -1; + } + else + { + error_count = 0; + return 0; + } } rtnval = fn_gnutls_record_recv (state, buf, nbyte); if (rtnval >= 0) --=-=-=--