From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#25391: 24.5; ffap-guesser "stack overflow in regexp matcher" error may crash emacs. Date: Fri, 13 Jan 2017 21:25:54 -0500 Message-ID: <874m12z8b1.fsf@users.sourceforge.net> References: <87vatqc8j1.fsf@gmail.com> <87y3yl1tdp.fsf@users.sourceforge.net> <8760lp8nqv.fsf@gmail.com> <87lgul167v.fsf@users.sourceforge.net> <87y3yk67l8.fsf@gmail.com> <87eg0b1qfj.fsf@users.sourceforge.net> <87mveztmd4.fsf@gmail.com> <8760ln11f3.fsf@users.sourceforge.net> <87r34bx9gx.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1484360721 1887 195.159.176.226 (14 Jan 2017 02:25:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Jan 2017 02:25:21 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 25391@debbugs.gnu.org To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 14 03:25:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSE1l-0007lZ-KS for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Jan 2017 03:25:09 +0100 Original-Received: from localhost ([::1]:46126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSE1p-0003xW-Rs for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 21:25:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSE1i-0003wH-Mh for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 21:25:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cSE1e-0002Ss-F1 for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 21:25:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37818) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cSE1e-0002Sk-AX for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 21:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cSE1e-00035D-2b for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 21:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Jan 2017 02:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25391 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25391-submit@debbugs.gnu.org id=B25391.148436069711836 (code B ref 25391); Sat, 14 Jan 2017 02:25:02 +0000 Original-Received: (at 25391) by debbugs.gnu.org; 14 Jan 2017 02:24:57 +0000 Original-Received: from localhost ([127.0.0.1]:53217 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSE1Y-00034q-SN for submit@debbugs.gnu.org; Fri, 13 Jan 2017 21:24:57 -0500 Original-Received: from mail-io0-f175.google.com ([209.85.223.175]:34125) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSE1X-00034f-Qa for 25391@debbugs.gnu.org; Fri, 13 Jan 2017 21:24:56 -0500 Original-Received: by mail-io0-f175.google.com with SMTP id l66so57552305ioi.1 for <25391@debbugs.gnu.org>; Fri, 13 Jan 2017 18:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=8lltspD6HaWWXF/V+BliTCZ5Wg0+/arVAAZxqA6QIC4=; b=Nnzj2sL7H33O8xXwK1csU+6R+bjCC6pP4dG5MlkQeW4djJK3avxDh2RbLGaz5R9TwJ bKwarqfwMvhDldKxG8srBZW9ZOc0+QSERbzg05A2p70xnOwk1PXvxZ9rxZLTfUEXxr1y b9ouLtYhBkT0LdKGmefRfUVhTk5wMKDo98AgnRaWldoEDFbxfg9GQtZbdd0KXdKQuVEm SXHF6fyUH3Zp/DKtbq0O1GP/KG+x/zCssGF3Df5QCBF404cQE0JxQ1CN05bxByKtHc3V DJmUFUBoCYJcGMRcOWhzOMpOyCA9atxfoiNuC1wkNcONXGsFibIra+lTL7i5rC2jkYM7 yl0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=8lltspD6HaWWXF/V+BliTCZ5Wg0+/arVAAZxqA6QIC4=; b=k34WgDgyhxU2jkAQNqCRTv3zZiU/g4lqMsR5jW98sM7YSwnKOGjf2kHWXm7OoYHNfd dLiu7GzkNmgbvibKCJ6ZjAB6PDL+PcvazNyI3mt3YVvMzhWcLYf6zVfiJ28VP2qFavSE hTF3Dhj+VUWKwuwE2nrqugDpESeEhSK8KQDCZWH/4PuKLQaBdD1Wm5rVdIOLySCzSyR0 fzx4BUButTmE6trB1ao/tgdaKlOveZTHv5QWa0OKjD+WIrGLOaFX3eU+53y0CAW/xpKU x/HwGelhn105/fDKuiAE6gwTl7yzyxowawoN0uBss0UYorDCParYgZA3dTYc2vCgRk4B JW7Q== X-Gm-Message-State: AIkVDXKWNOV6PCUSKJsMFPXpEKgbgNrluVJLQqlPbClCx0PAL/xKhzuTr+mTce4xC526AA== X-Received: by 10.107.197.133 with SMTP id v127mr3371002iof.119.1484360690282; Fri, 13 Jan 2017 18:24:50 -0800 (PST) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id z42sm1982798ita.6.2017.01.13.18.24.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jan 2017 18:24:49 -0800 (PST) In-Reply-To: <87r34bx9gx.fsf@gmail.com> (Thierry Volpiatto's message of "Tue, 10 Jan 2017 15:42:22 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:128097 Archived-At: --=-=-= Content-Type: text/plain Thierry Volpiatto writes: > npostavs@users.sourceforge.net writes: > >> Yes, although that's also true before my patch. So `ffap-gopher-regexp' >> never actually supported being changed. I'm not sure if it's a good >> idea to add support for that. > > I think it is, gopher is not widely used AFAIK, and allowing disabling > it would avoid needless search in most cases, thus it make it consistent > with other ffap* fns that can be disabled; I have a lot of complains at > helm with ffap annoyances and having more flexibility on this is interesting. Oh, yes, if the other regexps can be disabled like that, we should make it consistent. I've added a note about it to the docstring and toplevel comments; I'll push to master in a couple of days. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v4-0001-Improve-ffap-gopher-at-point-handling-of-long-lin.patch Content-Description: patch >From e4904a9c5c871780b94ffd2cf433637e5d75755a Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 8 Jan 2017 18:19:32 -0500 Subject: [PATCH v4] Improve ffap-gopher-at-point handling of long lines * lisp/ffap.el (ffap-gopher-regexp): Only match the KEY part. Note setting to nil is now supported. (ffap--gopher-var-on-line): New function. (ffap-gopher-at-point): Use it instead of the old ffap-gopher-regexp which could overflow the regexp stack on long lines (Bug#25391). Use `let-alist' instead of calling `set' on local variables. * test/lisp/ffap-tests.el (ffap-gopher-at-point): New test. --- lisp/ffap.el | 66 ++++++++++++++++++++++++++----------------------- test/lisp/ffap-tests.el | 17 +++++++++++++ 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/lisp/ffap.el b/lisp/ffap.el index 8144d41..0baf52b 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -76,6 +76,7 @@ ;; (setq ffap-machine-p-known 'accept) ; no pinging ;; (setq ffap-url-regexp nil) ; disable URL features in ffap ;; (setq ffap-shell-prompt-regexp nil) ; disable shell prompt stripping +;; (setq ffap-gopher-regexp nil) ; disable gopher bookmark matching ;; ;; ffap uses `browse-url' (if found, else `w3-fetch') to fetch URL's. ;; For a hairier `ffap-url-fetcher', try ffap-url.el (same ftp site). @@ -1194,43 +1195,46 @@ ffap-url-at-point val)))) (defvar ffap-gopher-regexp - "^.*\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *\\(.*\\) *$" - "Regexp matching a line in a gopher bookmark (maybe indented). -The two subexpressions are the KEY and VALUE.") + "\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *" + "Regexp matching a key in a gopher bookmark. +Set to nil to disable matching gopher bookmarks." + +(defun ffap--gopher-var-on-line () + "Return (KEY . VALUE) of gopher bookmark on current line." + (save-excursion + (let ((eol (progn (end-of-line) (skip-chars-backward " ") (point))) + (bol (progn (beginning-of-line) (point)))) + (when (re-search-forward ffap-gopher-regexp eol t) + (let ((key (match-string 1)) + (val (buffer-substring-no-properties (match-end 0) eol))) + (cons (intern (downcase key)) val)))))) (defun ffap-gopher-at-point () "If point is inside a gopher bookmark block, return its URL. Sets the variable `ffap-string-at-point-region' to the bounds of URL, if any." ;; `gopher-parse-bookmark' from gopher.el is not so robust - (save-excursion - (beginning-of-line) - (if (looking-at ffap-gopher-regexp) - (progn - (while (and (looking-at ffap-gopher-regexp) (not (bobp))) - (forward-line -1)) - (or (looking-at ffap-gopher-regexp) (forward-line 1)) - (setq ffap-string-at-point-region (list (point) (point))) - (let ((type "1") path host (port "70")) - (while (looking-at ffap-gopher-regexp) - (let ((var (intern - (downcase - (buffer-substring (match-beginning 1) - (match-end 1))))) - (val (buffer-substring (match-beginning 2) - (match-end 2)))) - (set var val) - (forward-line 1))) - (setcdr ffap-string-at-point-region (list (point))) - (if (and path (string-match "^ftp:.*@" path)) - (concat "ftp://" - (substring path 4 (1- (match-end 0))) - (substring path (match-end 0))) - (and (= (length type) 1) - host;; (ffap-machine-p host) - (concat "gopher://" host - (if (equal port "70") "" (concat ":" port)) - "/" type path)))))))) + (when (stringp ffap-gopher-regexp) + (save-excursion + (let* ((beg (progn (beginning-of-line) + (while (and (not (bobp)) (ffap--gopher-var-on-line)) + (forward-line -1)) + (point))) + (bookmark (cl-loop for keyval = (ffap--gopher-var-on-line) + while keyval collect keyval + do (forward-line 1)))) + (when bookmark + (setq ffap-string-at-point-region (list beg (point))) + (let-alist (nconc bookmark '((type . "1") (port . "70"))) + (if (and .path (string-match "\\`ftp:.*@" .path)) + (concat "ftp://" + (substring .path 4 (1- (match-end 0))) + (substring .path (match-end 0))) + (and (= (length .type) 1) + .host ;; (ffap-machine-p host) + (concat "gopher://" .host + (if (equal .port "70") "" (concat ":" .port)) + "/" .type .path))))))))) (defvar ffap-ftp-sans-slash-regexp (and diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el index 1ba5f86..a3fe350 100644 --- a/test/lisp/ffap-tests.el +++ b/test/lisp/ffap-tests.el @@ -49,6 +49,23 @@ (should (equal '(1 1) ffap-string-at-point-region))))) (and (file-exists-p file) (delete-file file))))) +(ert-deftest ffap-gopher-at-point () + (with-temp-buffer + (insert "\ +Type = 1 +Name = foo +Path = /the/path +Port = 7070 +Host = example.com\n") + (should-not (ffap-gopher-at-point)) + (goto-char (point-min)) + (should (equal (ffap-gopher-at-point) + "gopher://example.com:7070/1/the/path")) + (should (equal ffap-string-at-point-region + (list (point-min) (point-max)))) + (let ((ffap-gopher-regexp nil)) + (should-not (ffap-gopher-at-point))))) + (provide 'ffap-tests) ;;; ffap-tests.el ends here -- 2.9.3 --=-=-=--