From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?=C3=93scar?= Fuentes Newsgroups: gmane.emacs.bugs Subject: bug#36834: 27.0.50; [PATCH] password-cache.el: confuses key absence with nil password Date: Mon, 29 Jul 2019 07:12:03 +0200 Message-ID: <875znltof0.fsf@telefonica.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="136691"; mail-complaints-to="usenet@blaine.gmane.org" To: 36834@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jul 29 07:13:16 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hrxyF-000ZSk-S1 for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Jul 2019 07:13:15 +0200 Original-Received: from localhost ([::1]:49520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrxyE-00083o-A7 for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Jul 2019 01:13:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41023) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrxy5-00083e-EJ for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:13:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hrxy3-0007y1-OB for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:13:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hrxy2-0007wt-4r for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hrxy1-0000OA-SU for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C3=93scar?= Fuentes Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Jul 2019 05:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36834 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15643771331432 (code B ref -1); Mon, 29 Jul 2019 05:13:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Jul 2019 05:12:13 +0000 Original-Received: from localhost ([127.0.0.1]:47572 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrxxE-0000N2-Uv for submit@debbugs.gnu.org; Mon, 29 Jul 2019 01:12:13 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:35066) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hrxxD-0000Mv-Cl for submit@debbugs.gnu.org; Mon, 29 Jul 2019 01:12:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40747) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrxxC-00080F-8K for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:12:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hrxxB-0006EB-4B for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:12:10 -0400 Original-Received: from relayout03-redir.e.movistar.es ([86.109.101.203]:44747) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hrxxA-00069N-Pd for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2019 01:12:09 -0400 Original-Received: from sky (162.red-79-151-6.dynamicip.rima-tde.net [79.151.6.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 981711563@telefonica.net) by relayout03.e.movistar.es (Postfix) with ESMTPSA id 45xnqS3WVbzMl2b for ; Mon, 29 Jul 2019 07:12:04 +0200 (CEST) X-CTCH-Score: 0.000 X-CTCH-ScoreCust: 0.000 X-TnetOut-Country: IP: 79.151.6.162 | Country: ES X-TnetOut-Information: AntiSPAM and AntiVIRUS on relayout03 X-TnetOut-MsgID: 45xnqS3WVbzMl2b.AAD0A X-TnetOut-SpamCheck: no es spam, Unknown X-TnetOut-From: ofv@wanadoo.es X-TnetOut-Watermark: 1564981925.87401@HFFts58ZxH+Mb5q9FWZa8A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:164009 Archived-At: Recently observed that Gnus was creating lots of timers for password-cache-remove, about 6 every time that it fetched new news/mail. Upon inspection the cause was found in a change to password-cache.el: commit d66dcde46a87ee8a9064db3d9b05da9b17036f5b Author: Stefan Monnier Date: Fri Jul 28 12:27:00 2017 -0400 * lisp/password-cache.el (password-data): Use a hash-table * lisp/auth-source.el (auth-source-magic): Remove. (auth-source-forget+, auth-source-forget-all-cached): Adjust to new format of password-data. (auth-source-format-cache-entry): Just use a cons. (password-cache-remove, password-cache-add, password-reset) (password-read-from-cache, password-in-cache-p): Adjust accordingly. Fixes: bug#26699 The points of interest of that change are: (defun password-in-cache-p (key) "Check if KEY is in the cache." (and password-cache key - (intern-soft key password-data))) + (gethash key password-data))) and (defun password-cache-add (key password) "Add password to cache. The password is removed by a timer after `password-cache-expiry' seconds." - (when (and password-cache-expiry (null (intern-soft key password-data))) + (when (and password-cache-expiry (null (gethash key password-data))) The change uses gethash instead of intern-soft, but those functions act differently when the password (the value associated with the key) was nil. The effect is that every call to password-cache-add with nil as password creates a new timer, and password-in-cache-p returns nil if there exists a (key nil) entry on password-data, when previously it would return non-nil. So I propose this patch: diff --git a/lisp/password-cache.el b/lisp/password-cache.el index 5a09ae4859..6009fb491e 100644 --- a/lisp/password-cache.el +++ b/lisp/password-cache.el @@ -81,7 +81,8 @@ password-in-cache-p "Check if KEY is in the cache." (and password-cache key - (gethash key password-data))) + (not (eq (gethash key password-data 'password-cache-no-data) + 'password-cache-no-data)))) (defun password-read (prompt &optional key) "Read password, for use with KEY, from user, or from cache if wanted. @@ -125,7 +126,9 @@ password-cache-remove (defun password-cache-add (key password) "Add password to cache. The password is removed by a timer after `password-cache-expiry' seconds." - (when (and password-cache-expiry (null (gethash key password-data))) + (when (and password-cache-expiry + (eq (gethash key password-data 'password-cache-no-data) + 'password-cache-no-data)) (run-at-time password-cache-expiry nil #'password-cache-remove key)) Okay to commit? To emacs-26 or master? On another topic, before a cache entry is removed we try to overwrite the stored password (see password-cache-remove). However, the same change did this: (defun password-reset () "Clear the password cache." (interactive) - (fillarray password-data 0)) + (clrhash password-data)) I don't know if clrhash overwrites the data before releasing it.