From 99d2758343245de1ac452a9b8d1f4c1521f8c8d6 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 2 May 2012 17:34:57 -0400 Subject: [PATCH] * subr.el (read-passwd): Better clean after ourselves. Fixes: debbugs:11392 --- lisp/ChangeLog | 4 ++++ lisp/subr.el | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d2ab4b60c8b..40df0618c0e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2012-05-02 Stefan Monnier + + * subr.el (read-passwd): Better clean after ourselves (bug#11392). + 2012-05-02 Juanma Barranquero * notifications.el (dbus-debug): diff --git a/lisp/subr.el b/lisp/subr.el index b548f82ca5a..1f9f3aee9fa 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2115,21 +2115,21 @@ by doing (clear-string STRING)." (message "Password not repeated accurately; please start over") (sit-for 1)))) success) - (let (minibuf) + (let ((hide-chars-fun + (lambda (beg end _len) + (clear-this-command-keys) + (setq beg (min end (max (minibuffer-prompt-end) + beg))) + (dotimes (i (- end beg)) + (put-text-property (+ i beg) (+ 1 i beg) + 'display (string ?.))))) + minibuf) (minibuffer-with-setup-hook (lambda () (setq minibuf (current-buffer)) ;; Turn off electricity. (set (make-local-variable 'post-self-insert-hook) nil) - (add-hook 'after-change-functions - (lambda (beg end _len) - (clear-this-command-keys) - (setq beg (min end (max (minibuffer-prompt-end) - beg))) - (dotimes (i (- end beg)) - (put-text-property (+ i beg) (+ 1 i beg) - 'display (string ?.)))) - nil t)) + (add-hook 'after-change-functions hide-chars-fun nil 'local)) (unwind-protect (read-string prompt nil (let ((sym (make-symbol "forget-history"))) @@ -2137,7 +2137,14 @@ by doing (clear-string STRING)." sym) default) (when (buffer-live-p minibuf) - (with-current-buffer minibuf (erase-buffer)))))))) + (with-current-buffer minibuf + ;; Not sure why but it seems that there might be cases where the + ;; minibuffer is not always properly reset later on, so undo + ;; whatever we've done here (bug#11392). + (remove-hook 'after-change-functions hide-chars-fun 'local) + (kill-local-variable 'post-self-insert-hook) + ;; And of course, don't keep the sensitive data around. + (erase-buffer)))))))) ;; This should be used by `call-interactively' for `n' specs. (defun read-number (prompt &optional default) -- 2.39.2