From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#51263: 29.0.50; [PATCH] Use run-at-time to read a password in comint Date: Mon, 18 Oct 2021 13:54:59 +0200 Message-ID: <87k0ia4kfg.fsf@miha-pc> Reply-To: miha@kamnitnik.top Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17142"; mail-complaints-to="usenet@ciao.gmane.io" To: 51263@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 18 13:52:17 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 ) id 1mcRBg-00047R-KA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 13:52:17 +0200 Original-Received: from localhost ([::1]:37032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcRBf-0003AI-Gi for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 07:52:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcRBS-00038l-Tk for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 07:52:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcRBS-0007l3-GI for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 07:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mcRBS-0004RG-B0 for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 07:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: miha@kamnitnik.top Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Oct 2021 11:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51263 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.163455789517024 (code B ref -1); Mon, 18 Oct 2021 11:52:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Oct 2021 11:51:35 +0000 Original-Received: from localhost ([127.0.0.1]:46103 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcRB1-0004QW-4g for submit@debbugs.gnu.org; Mon, 18 Oct 2021 07:51:35 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:40046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcRAx-0004QM-Ma for submit@debbugs.gnu.org; Mon, 18 Oct 2021 07:51:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcRAw-0002rF-Gt for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 07:51:31 -0400 Original-Received: from kamnitnik.top ([2001:19f0:5001:bf2:5400:2ff:fee0:2626]:49010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcRAt-0007L0-Rb for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 07:51:29 -0400 Original-Received: from localhost (BSN-77-156-43.static.siol.net [193.77.156.43]) by kamnitnik.top (Postfix) with ESMTPSA id 5703E9C707 for ; Mon, 18 Oct 2021 11:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1634557883; bh=exna0SGpOm+cV4eMaBhoGbbNQAExaMbjcLNCGLzgLnY=; h=From:To:Subject:Date:From; b=wgLZpGmiMOu/uUuWw5wFCtEMp4cv1Wsi4sgaGiI0voNFzsooIJNOWqfNccxuXhwM1 zgQYkLF9j/J8GU9FPQdA5FIyaJN1th1YRcu1fChEucWrmBIoXkuu5O7PY1uXpvw9HA 9ksUGOe3xyIKrC/S0xX1d4wfFNs2LjkEqWa6sE9PZojmrPt+8PW9un/rT8gUhXhkQw sCWpDYHkfCzMWfpwCJnoVnh0PjlxZDTUZqYBOr+sJdqeM/XOlN/5y1cG98AQjhZoEV WirhFzDncVA7tNW6UqyYIV2PTRRFIdFM5qnmDkOj3t4lUIBqOYFx9Z8pQI5f/FTsj8 EqGsUbqCNOuGw== Received-SPF: pass client-ip=2001:19f0:5001:bf2:5400:2ff:fee0:2626; envelope-from=miha@kamnitnik.top; helo=kamnitnik.top X-Spam_score_int: 24 X-Spam_score: 2.4 X-Spam_bar: ++ X-Spam_report: (2.4 / 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, FROM_SUSPICIOUS_NTLD=0.499, FROM_SUSPICIOUS_NTLD_FP=1.999, PDS_OTHER_BAD_TLD=1.999, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:217475 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Currently, comint-watch-for-password-prompt has some problems. It is called from the comint process filter and doesn't return until the user exits the password minibuffer. If the process produces more output while the minibuffer is still open (this happens if the "sudo" command times out, for example), the process filter will be called recursively before the current execution of the process filter has a chance to finish. This filter function uses some global/buffer-local, state (the variable comint-last-output-start, for example), so it isn't made to be called simultaneously like that. The user may also quit the password minibuffer with C-g, canceling execution of the filter function. The result of these two events is usually that the buffer text containing the password prompt isn't correctly marked as output with the 'field text property. Further problems may arise if comint-output-filter-functions contain functions after the password prompt watcher. I've come up with a solution: using (run-at-time 0 ...), we can prompt for a password after the filter function finishes execution. The attached patch implements this for comint, eshell and term.el. Best regards. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-watch-for-password-prompt-Use-run-at-time-to-read-pa.patch Content-Transfer-Encoding: quoted-printable From=20d4e8af0f4d90c7d989f21781fc7ca7fd284652bf Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Mon, 18 Oct 2021 13:13:45 +0200 Subject: [PATCH] *-watch-for-password-prompt: Use run-at-time to read passw= ord * lisp/comint.el (comint-watch-for-password-prompt): * lisp/eshell/esh-mode.el (eshell-watch-for-password-prompt): * lisp/term.el (term-watch-for-password-prompt): Use run-at-time to read a password. =2D-- lisp/comint.el | 18 +++++++++++++----- lisp/eshell/esh-mode.el | 9 ++++++++- lisp/term.el | 9 ++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index a0873c0b6a..e925b3a4b6 100644 =2D-- a/lisp/comint.el +++ b/lisp/comint.el @@ -2455,11 +2455,19 @@ comint-watch-for-password-prompt (when (let ((case-fold-search t)) (string-match comint-password-prompt-regexp (string-replace "\r" "" string))) =2D (let ((comint--prompt-recursion-depth (1+ comint--prompt-recursion-d= epth))) =2D (if (> comint--prompt-recursion-depth 10) =2D (message "Password prompt recursion too deep") =2D (comint-send-invisible =2D (string-trim string "[ \n\r\t\v\f\b\a]+" "\n+")))))) + ;; Use `run-at-time' in order not to pause execution of the + ;; process filter with a minibuffer + (run-at-time + 0 nil + (lambda (current-buf) + (with-current-buffer current-buf + (let ((comint--prompt-recursion-depth + (1+ comint--prompt-recursion-depth))) + (if (> comint--prompt-recursion-depth 10) + (message "Password prompt recursion too deep") + (comint-send-invisible + (string-trim string "[ \n\r\t\v\f\b\a]+" "\n+")))))) + (current-buffer)))) ;; Low-level process communication =20 diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 98e89037f3..579b01f4d1 100644 =2D-- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -940,7 +940,14 @@ eshell-watch-for-password-prompt (beginning-of-line) (if (re-search-forward eshell-password-prompt-regexp eshell-last-output-end t) =2D (eshell-send-invisible)))))) + ;; Use `run-at-time' in order not to pause execution of + ;; the process filter with a minibuffer + (run-at-time + 0 nil + (lambda (current-buf) + (with-current-buffer current-buf + (eshell-send-invisible))) + (current-buffer))))))) =20 (custom-add-option 'eshell-output-filter-functions 'eshell-watch-for-password-prompt) diff --git a/lisp/term.el b/lisp/term.el index dd5457745b..530b93484e 100644 =2D-- a/lisp/term.el +++ b/lisp/term.el @@ -2409,7 +2409,14 @@ term-watch-for-password-prompt (when (term-in-line-mode) (when (let ((case-fold-search t)) (string-match comint-password-prompt-regexp string)) =2D (term-send-invisible (read-passwd string))))) + ;; Use `run-at-time' in order not to pause execution of the + ;; process filter with a minibuffer + (run-at-time + 0 nil + (lambda (current-buf) + (with-current-buffer current-buf + (term-send-invisible (read-passwd string)))) + (current-buffer))))) =20 ;;; Low-level process communication =2D-=20 2.33.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmFtYJMTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP0wWD/0S+j4XkLLP3QoeAW89Zpb14lYOfvqR 3VW9T84wUVfGuoxeuAbrxmQqMJoGJDaQUXableKWBEa2aI1LTxb4tM906Qsxq+r5 MprCg/BAYxVWZDpDU2hjLPv4pj8GOW45u538MLktgXqOAnYZaqBYT8kZRHGbGOui pvr+FneDP48vMBaRsLDVZVwKwZLUBAfeEW0MsL5omIrZ5/CrzqEivlzos2kAimUX zs0cK3hiEIxFOTWwt7Paf6xGzRinJWbswe1Rn1Sb3heVsz6rFFT/aQHqXp0++foX X5z6qvAqg8Q0EEdLNAcBCwqFf6UrNJ5nHm/zSZu0x565XCYx7OCFZ9vrpsTVgHmG YrowQ3ygCL7s/20P5kzXe2/vDZnwbx9sLdBJWKmWt/GpRmt1oVHr9Lb3LqKS8Ujq 3zKduP96ZNE817Y8Z6u86JEX3Cb4Myw62Bjkt33WGzZqM2niQM7EnRj05bVN6pO7 AuneMmKjnI5PcbmJE6zohcTn3v+MMzpijzM5Kzy5V39qrIxQaSaOdsGpagp7ms/s xLSCME0cvz/ZNGD0S0HP5R2rNsGe9qnF71j3OQ6uhmMKui2Ud4fO7zVn81n5wpIE UvSMnJCOdOvscJEl9Kzt2NUIdsL8pWpBYt4HaWBH/fRMYpmFonv1lzwG1CKGFsxX FUHsCeHK2kIryg== =2+CK -----END PGP SIGNATURE----- --==-=-=--