unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: charles@aurox.ch (Charles A. Roelli)
To: Eli Zaretskii <eliz@gnu.org>
Cc: 28350@debbugs.gnu.org
Subject: bug#28350: enriched.el code execution
Date: Sat, 09 Sep 2017 14:23:54 +0200	[thread overview]
Message-ID: <m2a8249i1x.fsf@aurox.ch> (raw)
In-Reply-To: <837exb1bk5.fsf@gnu.org> (message from Eli Zaretskii on Thu, 07 Sep 2017 05:34:34 +0300)

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

> Date: Thu, 07 Sep 2017 05:34:34 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> CC: 28350@debbugs.gnu.org
> 
> > Date: Wed, 06 Sep 2017 21:25:18 +0200
> > From: charles@aurox.ch (Charles A. Roelli)
> > 
> > As for a fix to apply to master: I'd like to keep "x-display" if we
> > can agree on some "safe" predicate that the given parameter would have
> > to satisfy.  Looking at the list of display specifications that are
> > available, it seems that simple string, margin text, space-width,
> > height (only in the (+ n), (- n) and n cases) and raise specifications
> > should be okay.  Does anybody else have an opinion about this?
> 
> I agree that the cases you have shown are safe.
> 
> Thanks.

Thank you.  Does the attached patch look OK?  I've used the file
enriched-test-safe-props.txt (also attached) to test that safe
properties are still applied.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Prevent-code-execution-by-text-enriched-files-Bug-28.patch --]
[-- Type: text/x-patch, Size: 2524 bytes --]

From 1c58b3e76a80a342c2f7e96d91214fe49678f471 Mon Sep 17 00:00:00 2001
From: "Charles A. Roelli" <charles@aurox.ch>
Date: Sat, 9 Sep 2017 14:03:58 +0200
Subject: [PATCH] Prevent code execution by text/enriched files (Bug#28350)

* lisp/textmodes/enriched.el (enriched-display-prop-safe-p): New
function.
(enriched-decode-display-prop): Use it to prevent unsafe display
properties from being applied.
---
 lisp/textmodes/enriched.el | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/lisp/textmodes/enriched.el b/lisp/textmodes/enriched.el
index 7ace2a5..f496259 100644
--- a/lisp/textmodes/enriched.el
+++ b/lisp/textmodes/enriched.el
@@ -503,6 +503,47 @@ enriched-decode-display-prop
 		  (error nil)))))
     (unless prop
       (message "Warning: invalid <x-display> parameter %s" param))
-    (list start end 'display prop)))
+    (if (enriched-display-prop-safe-p prop)
+        (list start end 'display prop)
+      (message "Warning: unsafe <x-display> parameter %s not applied" param)
+      (list start end))))
+
+(defun enriched-display-prop-safe-p (prop)
+  "Return t if display property PROP is safe to apply to text.
+
+A safe display property is either:
+
+  - a string,
+
+  - a space-width display specification, (space-width factor),
+    where FACTOR is an integer or a float,
+
+  - a margin display specification, ((margin right-margin) spec)
+    or ((margin left-margin) spec), where SPEC is a string,
+
+  - a height display specification, (height spec), where SPEC is
+    of the form (+ n), (- n) or n, and N is an integer,
+
+  - or a raise display specification, (raise factor), where
+    FACTOR is an integer.
+
+See Info node `(elisp)Display Property' for the use of these
+display specifications."
+  (ignore-errors
+    (or (stringp prop)
+        (and (eq (car prop) 'space-width)
+             (or (integerp (cadr prop)) (floatp (cadr prop))))
+        (and (consp (car prop))
+             (eq (caar prop) 'margin)
+             (or (eq (cadar prop) 'right-margin)
+                 (eq (cadar prop) 'left-margin))
+             (stringp (cadr prop)))
+        (and (eq (car prop) 'height)
+             (or (integerp (cadr prop))
+                 (and (listp (cadr prop))
+                      (or (eq (elt (cadr prop) 0) '+) (elt (cadr prop) 0) '-)
+                      (integerp (elt (cadr prop) 1)))))
+        (and (eq (car prop) 'raise)
+             (integerp (cadr prop))))))
 
 ;;; enriched.el ends here
-- 
2.9.4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: enriched-test-safe-props.txt --]
[-- Type: text/enriched, Size: 367 bytes --]

Content-Type: text/enriched
Text-Width: 70

<x-display><param>"replace"</param>test</x-display>

<x-display><param>(space-width 5)</param>large spaces</x-display>

<x-display><param>((margin left-margin) "string")</param>marginal text</x-display>

<x-display><param>(height 3)</param>tall text</x-display>

<x-display><param>(raise 5)</param>raised text</x-display>


  reply	other threads:[~2017-09-09 12:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 19:24 bug#28350: enriched.el code execution Charles A. Roelli
2017-09-06 19:25 ` Charles A. Roelli
2017-09-07  2:34   ` Eli Zaretskii
2017-09-09 12:23     ` Charles A. Roelli [this message]
2017-09-09 13:45       ` Eli Zaretskii
2017-09-09 15:57         ` Charles A. Roelli
2017-09-09 16:55           ` Eli Zaretskii
2017-09-09 20:37             ` Charles A. Roelli
2017-09-10 17:01               ` Eli Zaretskii
2017-09-11 16:32             ` Glenn Morris
2017-09-11 17:01               ` Eli Zaretskii
2017-09-09 22:43 ` Paul Eggert
2017-09-10 18:54   ` Charles A. Roelli
2017-09-10 21:46     ` Paul Eggert
2017-09-11  2:39       ` Eli Zaretskii
2017-09-11 14:22         ` Eli Zaretskii
2017-09-11 15:18     ` Eli Zaretskii
2017-09-11 18:44       ` Charles A. Roelli
2017-09-11 19:07         ` Eli Zaretskii
2017-09-16  9:48           ` Eli Zaretskii
2017-09-11 15:33   ` Glenn Morris
2017-09-11 16:38     ` Paul Eggert
2017-09-11 21:16       ` Glenn Morris
2017-09-12 19:59         ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2a8249i1x.fsf@aurox.ch \
    --to=charles@aurox.ch \
    --cc=28350@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).