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: Sat, 14 Jan 2017 01:57:40 -0500 Message-ID: <87vatixh5n.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> <874m12z8b1.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1484377041 12064 195.159.176.226 (14 Jan 2017 06:57:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 14 Jan 2017 06:57: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 07:57:17 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 1cSIGz-0001qi-2D for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Jan 2017 07:57:09 +0100 Original-Received: from localhost ([::1]:46739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSIH2-0007OX-6B for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 Jan 2017 01:57:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cSIGw-0007OR-5s for bug-gnu-emacs@gnu.org; Sat, 14 Jan 2017 01:57:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cSIGs-0006S8-7W for bug-gnu-emacs@gnu.org; Sat, 14 Jan 2017 01:57:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cSIGs-0006S3-25 for bug-gnu-emacs@gnu.org; Sat, 14 Jan 2017 01:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cSIGr-0000re-LO for bug-gnu-emacs@gnu.org; Sat, 14 Jan 2017 01:57:01 -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 06:57:01 +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.14843770043300 (code B ref 25391); Sat, 14 Jan 2017 06:57:01 +0000 Original-Received: (at 25391) by debbugs.gnu.org; 14 Jan 2017 06:56:44 +0000 Original-Received: from localhost ([127.0.0.1]:53281 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSIGa-0000r8-1G for submit@debbugs.gnu.org; Sat, 14 Jan 2017 01:56:44 -0500 Original-Received: from mail-it0-f53.google.com ([209.85.214.53]:38303) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cSIGY-0000qw-5x for 25391@debbugs.gnu.org; Sat, 14 Jan 2017 01:56:42 -0500 Original-Received: by mail-it0-f53.google.com with SMTP id x2so53465398itf.1 for <25391@debbugs.gnu.org>; Fri, 13 Jan 2017 22:56:42 -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=npjRCT2uPF9S9aDpGLi4bKpJMVApo/wRVdzT20x0a9I=; b=uchxX1IsH6rgseMieHIQ8QLAE47DVNHzoRlmYemamyb472VkQr6HZskIm5D0roLWWu BNcVFi/BWZngqq3pWM4+b78+AYTeVukV9kD4XXhJykid0PuBv85b/xxymZ73OxTEX7AC aVQ0o0uWZ7svc0+fdgxpF1A0bG8ckuoHsUpYpGBXp84ErgcElpwvE+GTWmAWkKxBgbtm 04COm58g4x777QWza0Jy3e6D7GOdRuDc7Ty+dCf8mTjoyUomQ+FO0en9FKD5ppUF2QlQ T8g6rm59MeiqzOuvpABHvtKUUDrciTBCXqtzFDBa8oeLJsE+rLnDSCeOb9LZXSHL+ucm vf6Q== 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=npjRCT2uPF9S9aDpGLi4bKpJMVApo/wRVdzT20x0a9I=; b=DW0GDQQ5HbL4IpTG87lYgl2tNaRzOSrF72ab13jKXusO5jNTZvvLdKw1T6JPrMR8ix C0nG1MS/RTk5CcIwhmBoCDlGHKBF1c6Ar10AuRmOae8vNEQSt3INV6Me8GpCUzbf8wer 2n6krUJlmw4rbUdyYWCBXMO3bqtg4ts3H2gm/Fc42VO5CROCuURFhZl+Bq5tYJHotPBs yfqN9yzAhaFWbjaRT9s1WNz2SCNOxtsLv/s8EfEsN+LJ0jttiemxXz2/M+7NUWSLspX2 3B5F6GTeRK6Cbq2V+9tJQS34z4gjdp5zuNP0mZhIkW6/e+qrBYGQy4s48s3gLNCV3DGf X7SQ== X-Gm-Message-State: AIkVDXLL6Nk9J39Ni51kJ8plJwPz19pIzgq3XqbIy2czdhVEFKfROK9Pj27uUI6sFLPg3Q== X-Received: by 10.36.50.78 with SMTP id j75mr6442737ita.58.1484376996502; Fri, 13 Jan 2017 22:56:36 -0800 (PST) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id w192sm2293723itw.3.2017.01.13.22.56.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jan 2017 22:56:35 -0800 (PST) In-Reply-To: <874m12z8b1.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Fri, 13 Jan 2017 21:25:54 -0500") 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:128107 Archived-At: --=-=-= Content-Type: text/plain npostavs@users.sourceforge.net writes: > (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." Oops, lost a close paren. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v5-0001-Improve-ffap-gopher-at-point-handling-of-long-lin.patch Content-Description: patch >From 98e9ff3cb73acc5e177abc907f05bb8e3ff09712 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 8 Jan 2017 18:19:32 -0500 Subject: [PATCH v5] 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..068897b 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 --=-=-=--