diff options
| author | Ihor Radchenko | 2024-02-20 12:19:46 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2024-03-24 08:38:48 -0400 |
| commit | befa9fcaae29a6c9a283ba371c3c5234c7f644eb (patch) | |
| tree | 426cc115202de3b0221814920698cb79e04c51c0 | |
| parent | 3221d8d46116fdefb19742be916d0e352dfab761 (diff) | |
| download | emacs-befa9fcaae29a6c9a283ba371c3c5234c7f644eb.tar.gz emacs-befa9fcaae29a6c9a283ba371c3c5234c7f644eb.zip | |
org-macro--set-templates: Prevent code evaluation
* lisp/org/org-macro.el (org-macro--set-templates): Get rid of any
risk to evaluate code when `org-macro--set-templates' is called as a
part of major mode initialization. This way, no code evaluation is
ever triggered when user merely opens the file or when
`mm-display-org-inline' invokes Org major mode to fontify mime part
preview in email messages.
| -rw-r--r-- | lisp/org/org-macro.el | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lisp/org/org-macro.el b/lisp/org/org-macro.el index 776d162be12..0be51eec512 100644 --- a/lisp/org/org-macro.el +++ b/lisp/org/org-macro.el | |||
| @@ -109,6 +109,13 @@ previous one, unless VALUE is nil. Return the updated list." | |||
| 109 | (let ((new-templates nil)) | 109 | (let ((new-templates nil)) |
| 110 | (pcase-dolist (`(,name . ,value) templates) | 110 | (pcase-dolist (`(,name . ,value) templates) |
| 111 | (let ((old-definition (assoc name new-templates))) | 111 | (let ((old-definition (assoc name new-templates))) |
| 112 | ;; This code can be evaluated unconditionally, as a part of | ||
| 113 | ;; loading Org mode. We *must not* evaluate any code present | ||
| 114 | ;; inside the Org buffer while loading. Org buffers may come | ||
| 115 | ;; from various sources, like received email messages from | ||
| 116 | ;; potentially malicious senders. Org mode might be used to | ||
| 117 | ;; preview such messages and no code evaluation from inside the | ||
| 118 | ;; received Org text should ever happen without user consent. | ||
| 112 | (when (and (stringp value) (string-match-p "\\`(eval\\>" value)) | 119 | (when (and (stringp value) (string-match-p "\\`(eval\\>" value)) |
| 113 | ;; Pre-process the evaluation form for faster macro expansion. | 120 | ;; Pre-process the evaluation form for faster macro expansion. |
| 114 | (let* ((args (org-macro--makeargs value)) | 121 | (let* ((args (org-macro--makeargs value)) |
| @@ -121,7 +128,7 @@ previous one, unless VALUE is nil. Return the updated list." | |||
| 121 | (cadr (read value)) | 128 | (cadr (read value)) |
| 122 | (error | 129 | (error |
| 123 | (user-error "Invalid definition for macro %S" name))))) | 130 | (user-error "Invalid definition for macro %S" name))))) |
| 124 | (setq value (eval (macroexpand-all `(lambda ,args ,body)) t)))) | 131 | (setq value `(lambda ,args ,body)))) |
| 125 | (cond ((and value old-definition) (setcdr old-definition value)) | 132 | (cond ((and value old-definition) (setcdr old-definition value)) |
| 126 | (old-definition) | 133 | (old-definition) |
| 127 | (t (push (cons name (or value "")) new-templates))))) | 134 | (t (push (cons name (or value "")) new-templates))))) |