From: Lars Ingebrigtsen Date: Mon, 19 Sep 2022 07:42:28 +0000 (+0200) Subject: Don't save bookmark context from encrypted files X-Git-Tag: emacs-29.0.90~1856^2~376 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a53781470935fc0b7c7e576c3d02ed723c9587c4;p=emacs.git Don't save bookmark context from encrypted files * doc/emacs/regs.texi (Bookmarks): Mention this. * lisp/bookmark.el (bookmark-make-record): Don't include context in encrypted files (bug#57856). * lisp/epa-hook.el (epa-file-name-p): New function. --- diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index fb936018798..ef9187bb9a6 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -381,7 +381,8 @@ jump to the bookmark. @code{bookmark-jump} can find the proper position even if the file is modified slightly. The variable @code{bookmark-search-size} says how many characters of context to record on each side of the bookmark's -position. +position. (In buffers that are visiting encrypted files, no context +is saved in the bookmarks file no matter the value of this variable.) Here are some additional commands for working with bookmarks: diff --git a/etc/NEWS b/etc/NEWS index e5d9b1ca23d..a739d74b650 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -180,6 +180,11 @@ of 'user-emacs-directory'. * Incompatible changes in Emacs 29.1 ++++ +*** bookmarks no longer include context for encrypted files. +If you're visiting an encrypted file, setting a bookmark no longer +includes excerpts from that buffer in the bookmarks file. + --- *** 'show-paren-mode' is now disabled in 'special-mode' buffers. In Emacs versions previous to Emacs 28.1, 'show-paren-mode' defaulted diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 8dfc16bf9fa..f150a24bbfb 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -594,7 +594,18 @@ equivalently just return ALIST without NAME.") (defun bookmark-make-record () "Return a new bookmark record (NAME . ALIST) for the current location." - (let ((record (funcall bookmark-make-record-function))) + (let* ((bookmark-search-size + ;; If we're in a buffer that's visiting an encrypted file, + ;; don't include any context in the bookmark file, because + ;; that would leak (possibly secret) data. + (if (and buffer-file-name + (or (and (fboundp 'epa-file-name-p) + (epa-file-name-p buffer-file-name)) + (and (fboundp 'tramp-crypt-file-name-p) + (tramp-crypt-file-name-p buffer-file-name)))) + 0 + bookmark-search-size)) + (record (funcall bookmark-make-record-function))) ;; Set up default name if the function does not provide one. (unless (stringp (car record)) (if (car record) (push nil record)) diff --git a/lisp/epa-hook.el b/lisp/epa-hook.el index 18e47c682e8..70c30308819 100644 --- a/lisp/epa-hook.el +++ b/lisp/epa-hook.el @@ -88,6 +88,10 @@ interface, update `file-name-handler-alist'." epa-file-inhibit-auto-save) (auto-save-mode 0))) +(defun epa-file-name-p (file) + "Say whether FILE is handled by `epa-file'." + (and auto-encryption-mode (string-match-p epa-file-name-regexp file))) + (define-minor-mode auto-encryption-mode "Toggle automatic file encryption/decryption (Auto Encryption mode)." :global t :init-value t :group 'epa-file :version "23.1"