From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Manuel Giraud <manuel@ledu-giraud.fr>
Newsgroups: gmane.emacs.devel
Subject: [Patch] Avoid recording chars when reading passwords
Date: Wed, 08 Jun 2022 15:46:19 +0200
Message-ID: <87edzz8dzo.fsf@elite.giraud>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="14386"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix)
To: emacs-devel@gnu.org
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jun 08 15:47:18 2022
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1nyw1m-0003Vv-TC
	for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Jun 2022 15:47:18 +0200
Original-Received: from localhost ([::1]:39750 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1nyw1l-0006YR-KP
	for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Jun 2022 09:47:17 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46400)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <manuel@ledu-giraud.fr>)
 id 1nyw0v-0005nN-Hj
 for emacs-devel@gnu.org; Wed, 08 Jun 2022 09:46:25 -0400
Original-Received: from ledu-giraud.fr ([51.159.28.247]:7307)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <manuel@ledu-giraud.fr>)
 id 1nyw0t-0003AT-AN
 for emacs-devel@gnu.org; Wed, 08 Jun 2022 09:46:25 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=itrDZjEwdWPQ4Ha/
 tBkl9VcHCo2j0Ntjqw/h5vabljI=; h=date:subject:to:from;
 d=ledu-giraud.fr; b=la7zfJP/McuytU5gPP6M54jE1z/z31Kg5tXYDbzZDcsGkxqe6f
 EKZGGaeIszBKLMrrZHMk4BPV8EvatT+43hDAjsmSlRQgU16ncfZigR4Ixw/CcZ9RNYflKv
 fmphcosiDHBDqBMGpeRLljdcJLlfKtyc4p5HiovdCaBQzGzL+6BfjF4oVr7wwqeOhXcyV2
 KuL/w7KT77ezmLeGDStmJ83vIbc1jFv+oVleaie8UepzErgMYEElyNqfjDh/vFHqo+mxZh
 zeY693O7d9FIYw+hG9cklrOIXrqajb5j/eH7QQXU4UhWhuiFEz4oCxtW/BtRHJzDyf+nVX
 mX7pak9ojesw==
Original-Received: from elite.giraud (<unknown> [10.1.1.1])
 by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 08c059ca
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <emacs-devel@gnu.org>;
 Wed, 8 Jun 2022 15:46:20 +0200 (CEST)
Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr;
 helo=ledu-giraud.fr
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: "Emacs-devel"
 <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Xref: news.gmane.io gmane.emacs.devel:290932
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/290932>

--=-=-=
Content-Type: text/plain

Hi,

With this patch, passwords won't appear in the lossage or the dribble
file.

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-Avoid-recording-chars-when-reading-passwords.patch

>From a15d43e2cd80307e2597f7888a4920d73fa58362 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Wed, 8 Jun 2022 15:39:39 +0200
Subject: [PATCH] Avoid recording chars when reading passwords

* lisp/subr.el (read-passwd): inhibit char recording when reading
a password.
* src/keyboard.c (syms_of_keyboard, read_char): introduce
`do-not-record-char' to inhibit char recording.
---
 lisp/subr.el   |  1 +
 src/keyboard.c | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 50ae357a13..1007237fb6 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3048,6 +3048,7 @@ read-passwd
             (use-local-map read-passwd-map)
             (setq-local inhibit-modification-hooks nil) ;bug#15501.
 	    (setq-local show-paren-mode nil)		;bug#16091.
+            (setq-local do-not-record-char t)
             (add-hook 'post-command-hook #'read-password--hide-password nil t))
         (unwind-protect
             (let ((enable-recursive-minibuffers t)
diff --git a/src/keyboard.c b/src/keyboard.c
index 55d710ed62..a628c2d2df 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3046,10 +3046,13 @@ read_char (int commandflag, Lisp_Object map,
 
   /* Store these characters into recent_keys, the dribble file if any,
      and the keyboard macro being defined, if any.  */
-  record_char (c);
-  recorded = true;
-  if (! NILP (also_record))
-    record_char (also_record);
+  if (!do_not_record_char)
+    {
+      record_char (c);
+      recorded = true;
+      if (! NILP (also_record))
+	record_char (also_record);
+    }
 
   /* Wipe the echo area.
      But first, if we are about to use an input method,
@@ -3172,7 +3175,7 @@ read_char (int commandflag, Lisp_Object map,
   /* When we consume events from the various unread-*-events lists, we
      bypass the code that records input, so record these events now if
      they were not recorded already.  */
-  if (!recorded)
+  if (!recorded && !do_not_record_char)
     {
       record_char (c);
       recorded = true;
@@ -12561,6 +12564,11 @@ syms_of_keyboard (void)
 \(Even if the operating system has support for stopping a process.)  */);
   cannot_suspend = false;
 
+  DEFVAR_BOOL ("do-not-record-char", do_not_record_char,
+	       doc: /* Non-nil means to not record chars.
+Those chars would not appear in the dribble file or in `view-lossage'.  */);
+  do_not_record_char = false;
+
   DEFVAR_BOOL ("menu-prompting", menu_prompting,
 	       doc: /* Non-nil means prompt with menus when appropriate.
 This is done when reading from a keymap that has a prompt string,
-- 
2.36.0


--=-=-=
Content-Type: text/plain

-- 
Manuel Giraud

--=-=-=--