[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 301ee3d 2/2: Avoid a regexp overflow in message-got
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 301ee3d 2/2: Avoid a regexp overflow in message-goto-body |
Date: |
Thu, 26 Jan 2017 20:12:45 +0000 (UTC) |
branch: master
commit 301ee3d0319d489087bc548beb2ea5e7900224b6
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Avoid a regexp overflow in message-goto-body
* lisp/gnus/message.el (message-goto-body-1): Avoid using a
complicated backtracking regexp, because they may overflow on
large headers (bug#21160).
---
lisp/gnus/message.el | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index ce0d976..9af38c0 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -3111,16 +3111,26 @@ M-RET `message-newline-and-reformat' (break the line
and reformat)."
(message-goto-body-1))
(defun message-goto-body-1 ()
+ "Go to the body and return point."
(goto-char (point-min))
(or (search-forward (concat "\n" mail-header-separator "\n") nil t)
- (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
+ ;; If the message is mangled, find the end of the headers the
+ ;; hard way.
+ (progn
+ ;; Skip past all headers and continuation lines.
+ (while (looking-at "[^:]+:\\|[\t ]+[^\t ]")
+ (forward-line 1))
+ ;; We're now at the first empty line, so perhaps move past it.
+ (when (and (eolp)
+ (not (eobp)))
+ (forward-line 1))
+ (point))))
(defun message-in-body-p ()
"Return t if point is in the message body."
(>= (point)
(save-excursion
- (message-goto-body-1)
- (point))))
+ (message-goto-body-1))))
(defun message-goto-eoh ()
"Move point to the end of the headers."