diff options
Diffstat (limited to 'meta-oe/recipes-support/emacs/files/0001-org-link-expand-abbrev-Do-not-evaluate-arbitrary-uns.patch')
| -rw-r--r-- | meta-oe/recipes-support/emacs/files/0001-org-link-expand-abbrev-Do-not-evaluate-arbitrary-uns.patch | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/emacs/files/0001-org-link-expand-abbrev-Do-not-evaluate-arbitrary-uns.patch b/meta-oe/recipes-support/emacs/files/0001-org-link-expand-abbrev-Do-not-evaluate-arbitrary-uns.patch new file mode 100644 index 0000000000..88fdaaf22d --- /dev/null +++ b/meta-oe/recipes-support/emacs/files/0001-org-link-expand-abbrev-Do-not-evaluate-arbitrary-uns.patch | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | From 8b8866eb94c7b7140ba94eb2b4e6ead14c0d986d Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Ihor Radchenko <yantar92@posteo.net> | ||
| 3 | Date: Fri, 21 Jun 2024 15:45:25 +0200 | ||
| 4 | Subject: [PATCH] org-link-expand-abbrev: Do not evaluate arbitrary unsafe | ||
| 5 | Elisp code | ||
| 6 | |||
| 7 | * lisp/org/ol.el (org-link-expand-abbrev): Refuse expanding %(...) | ||
| 8 | link abbrevs that specify unsafe function. Instead, display a | ||
| 9 | warning, and do not expand the abbrev. Clear all the text properties | ||
| 10 | from the returned link, to avoid any potential vulnerabilities caused | ||
| 11 | by properties that may contain arbitrary Elisp. | ||
| 12 | |||
| 13 | CVE: CVE-2024-39331 | ||
| 14 | Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=c645e1d8205f0f0663ec4a2d27575b238c646c7c] | ||
| 15 | |||
| 16 | Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com> | ||
| 17 | --- | ||
| 18 | lisp/org/ol.el | 40 +++++++++++++++++++++++++++++----------- | ||
| 19 | 1 file changed, 29 insertions(+), 11 deletions(-) | ||
| 20 | |||
| 21 | diff --git a/lisp/org/ol.el b/lisp/org/ol.el | ||
| 22 | index 9ad191c..c15128f 100644 | ||
| 23 | --- a/lisp/org/ol.el | ||
| 24 | +++ b/lisp/org/ol.el | ||
| 25 | @@ -1063,17 +1063,35 @@ Abbreviations are defined in `org-link-abbrev-alist'." | ||
| 26 | (if (not as) | ||
| 27 | link | ||
| 28 | (setq rpl (cdr as)) | ||
| 29 | - (cond | ||
| 30 | - ((symbolp rpl) (funcall rpl tag)) | ||
| 31 | - ((string-match "%(\\([^)]+\\))" rpl) | ||
| 32 | - (replace-match | ||
| 33 | - (save-match-data | ||
| 34 | - (funcall (intern-soft (match-string 1 rpl)) tag)) | ||
| 35 | - t t rpl)) | ||
| 36 | - ((string-match "%s" rpl) (replace-match (or tag "") t t rpl)) | ||
| 37 | - ((string-match "%h" rpl) | ||
| 38 | - (replace-match (url-hexify-string (or tag "")) t t rpl)) | ||
| 39 | - (t (concat rpl tag))))))) | ||
| 40 | + ;; Drop any potentially dangerous text properties like | ||
| 41 | + ;; `modification-hooks' that may be used as an attack vector. | ||
| 42 | + (substring-no-properties | ||
| 43 | + (cond | ||
| 44 | + ((symbolp rpl) (funcall rpl tag)) | ||
| 45 | + ((string-match "%(\\([^)]+\\))" rpl) | ||
| 46 | + (let ((rpl-fun-symbol (intern-soft (match-string 1 rpl)))) | ||
| 47 | + ;; Using `unsafep-function' is not quite enough because | ||
| 48 | + ;; Emacs considers functions like `genenv' safe, while | ||
| 49 | + ;; they can potentially be used to expose private system | ||
| 50 | + ;; data to attacker if abbreviated link is clicked. | ||
| 51 | + (if (or (eq t (get rpl-fun-symbol 'org-link-abbrev-safe)) | ||
| 52 | + (eq t (get rpl-fun-symbol 'pure))) | ||
| 53 | + (replace-match | ||
| 54 | + (save-match-data | ||
| 55 | + (funcall (intern-soft (match-string 1 rpl)) tag)) | ||
| 56 | + t t rpl) | ||
| 57 | + (org-display-warning | ||
| 58 | + (format "Disabling unsafe link abbrev: %s | ||
| 59 | +You may mark function safe via (put '%s 'org-link-abbrev-safe t)" | ||
| 60 | + rpl (match-string 1 rpl))) | ||
| 61 | + (setq org-link-abbrev-alist-local (delete as org-link-abbrev-alist-local) | ||
| 62 | + org-link-abbrev-alist (delete as org-link-abbrev-alist)) | ||
| 63 | + link | ||
| 64 | + ))) | ||
| 65 | + ((string-match "%s" rpl) (replace-match (or tag "") t t rpl)) | ||
| 66 | + ((string-match "%h" rpl) | ||
| 67 | + (replace-match (url-hexify-string (or tag "")) t t rpl)) | ||
| 68 | + (t (concat rpl tag)))))))) | ||
| 69 | |||
| 70 | (defun org-link-open (link &optional arg) | ||
| 71 | "Open a link object LINK. | ||
