unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
@ 2022-07-01 12:03 Jan Synáček
  2022-07-02 12:28 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Synáček @ 2022-07-01 12:03 UTC (permalink / raw)
  To: 56336


When the output from a command spawned with 'M-&' (async-shell-command)
ends with "password:" Emacs prompts for a password.

Reproducer:
0) $ cat /tmp/test.txt
   enter your password:
1) emacs -Q
2) Press 'M-&', enter 'cat /tmp/test.txt' as input and hit enter.
3) Emacs prompts for a password.

I expect that 3) should not happen as the output is simply to stdout and
no stdin input is expected. Note that the reproducer is minimal and a
bit contrived but the real bug showed itself when I was running a big
test suite that contained several lines ending with "password:" in its
output.

I've also tested this with the latest master (commit
3a4c408a7b6f3df5ca0eb4a406efbdb4899e9742), where it sometimes happens as
well and sometimes you just get an error like this:

Error running timer: (error "Buffer *Async Shell Command* has no process")


In GNU Emacs 28.1.90 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6)
 of 2022-07-01 built on jsynacek-home
Repository revision: 7e33618bbc07b65c36744db8e7ef219d2d942456
Repository branch: emacs-28
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Arch Linux

Configured using:
 'configure --with-imagemagick --with-json --with-native-compilation
 --prefix=/home/jsynacek/emacs'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ
IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Dired by name

Minor modes in effect:
  windmove-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  global-so-long-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/jsynacek/.emacs.d/elpa/transient-20220514.945/transient hides /home/jsynacek/emacs/share/emacs/28.1.90/lisp/transient

Features:
(shadow sort mail-extr emacsbug tabify man windmove vc-mtn vc-hg vc-bzr
vc-src vc-sccs vc-svn vc-cvs vc-rcs counsel xdg swiper misearch
multi-isearch vc-git magit-extras face-remap dired-aux haskell-lite
github-actions-lite cabal-project-lite cabal-lite dockerfile-lite
the-org-mode-expansions org-element avl-tree org ob ob-tangle ob-ref
ob-lob ob-table ob-exp org-macro org-footnote org-src ob-comint
org-pcomplete org-list org-faces org-entities org-version ob-emacs-lisp
ob-core ob-eval org-table oc-basic bibtex iso8601 ol org-keys oc
org-compat org-macs org-loaddefs find-func cal-menu calendar
cal-loaddefs vc-dir ewoc slime etags fileloop generator xref project
arc-mode archive-mode noutline outline hyperspec rg files-x vc
vc-dispatcher rg-info-hack rg-menu rg-ibuffer rg-result wgrep-rg wgrep
rg-history rg-header ibuf-ext ibuffer ibuffer-loaddefs grep cus-edit pp
cus-load wid-edit pulse magit-submodule magit-obsolete magit-blame
magit-stash magit-reflog magit-bisect magit-push magit-pull magit-fetch
magit-clone magit-remote magit-commit magit-sequence magit-notes
magit-worktree magit-tag magit-merge magit-branch magit-reset
magit-files magit-refs magit-status magit magit-repos magit-apply
magit-wip magit-log which-func imenu magit-diff smerge-mode diff
diff-mode git-commit log-edit easy-mmode message rmc puny rfc822 mml
mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader pcvs-util add-log magit-core
magit-autorevert autorevert filenotify magit-margin magit-transient
magit-process with-editor magit-mode magit-git magit-base magit-section
crm dash compat-27 compat-26 jsynacek-text jsynacek-term term disp-table
shell pcomplete ehelp jsynacek-project ivy delsel ivy-faces ivy-overlay
colir color expand-region text-mode-expansions er-basic-expansions
thingatpt expand-region-core advice expand-region-custom dired
dired-loaddefs avy transient time-date format-spec compat edmacro kmacro
jsynacek-misc jsynacek-elisp smtpmail sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils so-long open-color server
compile text-property-search comint ansi-color ring slime-autoloads info
package browse-url url url-proxy url-privacy url-expand url-methods
url-history url-cookie url-domsuf url-util mailcap url-handlers
url-parse auth-source eieio eieio-core eieio-loaddefs password-cache
json map url-vars comp comp-cstr warnings subr-x rx cl-seq cl-macs
cl-extra help-mode seq byte-opt gv cl-loaddefs cl-lib bytecomp
byte-compile cconv iso-transl tooltip eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 625701 124605)
 (symbols 48 28318 7)
 (strings 32 137451 11163)
 (string-bytes 1 4439546)
 (vectors 16 65984)
 (vector-slots 8 1019313 83933)
 (floats 8 312 708)
 (intervals 56 17397 65)
 (buffers 992 42))





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-01 12:03 bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:" Jan Synáček
@ 2022-07-02 12:28 ` Lars Ingebrigtsen
  2022-07-03  7:53   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-03 16:54   ` Jan Synáček
  0 siblings, 2 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-02 12:28 UTC (permalink / raw)
  To: Jan Synáček; +Cc: 56336

Jan Synáček <jan.synacek@gmail.com> writes:

> When the output from a command spawned with 'M-&' (async-shell-command)
> ends with "password:" Emacs prompts for a password.
>
> Reproducer:
> 0) $ cat /tmp/test.txt
>    enter your password:
> 1) emacs -Q
> 2) Press 'M-&', enter 'cat /tmp/test.txt' as input and hit enter.
> 3) Emacs prompts for a password.
>
> I expect that 3) should not happen as the output is simply to stdout and
> no stdin input is expected. Note that the reproducer is minimal and a
> bit contrived but the real bug showed itself when I was running a big
> test suite that contained several lines ending with "password:" in its
> output.
>
> I've also tested this with the latest master (commit
> 3a4c408a7b6f3df5ca0eb4a406efbdb4899e9742), where it sometimes happens as
> well and sometimes you just get an error like this:
>
> Error running timer: (error "Buffer *Async Shell Command* has no process")

I've now fixed the latter in Emacs 29.

The former problem is rather intractable.  That is, if you say

ssh foo@host

you'll get a password prompt as the final line in the buffer, and Emacs
will ask you to enter a password.

If you say

echo -n "password: "; sleep 10; echo foo

then there's no way for Emacs to distinguish that from the ssh
situation: It sees a prompt as the last thing in the buffer, and Emacs
can't possibly know that that's not a process asking for a password.

Note that

echo "password: "; echo foo; sleep 10

won't ask for a password.

So I don't know that there's any way to fix this -- Emacs uses a
heuristic, and it will be wrong in some cases.

Or does anybody have any ideas here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-02 12:28 ` Lars Ingebrigtsen
@ 2022-07-03  7:53   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-07-03 12:19     ` Lars Ingebrigtsen
  2022-07-03 16:54   ` Jan Synáček
  1 sibling, 1 reply; 7+ messages in thread
From: miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-07-03  7:53 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Jan Synáček; +Cc: 56336

[-- Attachment #1: Type: text/plain, Size: 233 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I've now fixed the latter in Emacs 29.

Thanks. I think an equivalent change could be made for
eshell-watch-for-password-prompt and term-watch-for-password-prompt as
well.

Best regards.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-03  7:53   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-03 12:19     ` Lars Ingebrigtsen
  2022-08-02 11:02       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-03 12:19 UTC (permalink / raw)
  To: miha; +Cc: 56336, Jan Synáček

miha@kamnitnik.top writes:

> Thanks. I think an equivalent change could be made for
> eshell-watch-for-password-prompt and term-watch-for-password-prompt as
> well.

Are they used in contexts where this is meaningful?  I.e., used from
commands like `M-&' that kill off the shell?

But I guess for resilience it doesn't hurt...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-02 12:28 ` Lars Ingebrigtsen
  2022-07-03  7:53   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-07-03 16:54   ` Jan Synáček
  2022-07-04 10:53     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Synáček @ 2022-07-03 16:54 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56336

On Sat, Jul 2, 2022 at 2:28 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
> The former problem is rather intractable.  That is, if you say
>
> ssh foo@host
>
> you'll get a password prompt as the final line in the buffer, and Emacs
> will ask you to enter a password.
>
> If you say
>
> echo -n "password: "; sleep 10; echo foo
>
> then there's no way for Emacs to distinguish that from the ssh
> situation: It sees a prompt as the last thing in the buffer, and Emacs
> can't possibly know that that's not a process asking for a password.
>
> Note that
>
> echo "password: "; echo foo; sleep 10
>
> won't ask for a password.
>
> So I don't know that there's any way to fix this -- Emacs uses a
> heuristic, and it will be wrong in some cases.
>
> Or does anybody have any ideas here?

Well, I know about one thing that might work well enough as an
additional heuristic just for this case.

It seems that if a command only outputs to stdout (and probably to
stderr as well) and doesn't really ask for input, lsof -p <that async
process> shows something like this:
$ lsof -p 145475
...
sleep   145475 jsynacek    0u   CHR  136,1      0t0        4 /dev/pts/1
sleep   145475 jsynacek    1u   CHR  136,1      0t0        4 /dev/pts/1
sleep   145475 jsynacek    2u   CHR  136,1      0t0        4 /dev/pts/1

Whereas if the command really wants input ('ssh jsynacek@localhost' in
this particular example), it looks like the following:
$ lsof -p 145512
...
ssh     145512 jsynacek    0u   CHR              136,1      0t0
4 /dev/pts/1
ssh     145512 jsynacek    1u   CHR              136,1      0t0
4 /dev/pts/1
ssh     145512 jsynacek    2u   CHR              136,1      0t0
4 /dev/pts/1
ssh     145512 jsynacek    3u  IPv6             203802      0t0
TCP localhost:32864->localhost:ssh (ESTABLISHED)
ssh     145512 jsynacek    4u  unix 0x000000006034f025      0t0
203803 type=STREAM (CONNECTED)
ssh     145512 jsynacek    5u   CHR                5,0      0t0
11 /dev/tty

Note the /dev/tty in the output. I'm not sure, but I think this might
be good enough.

-- 
Jan Synáček





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-03 16:54   ` Jan Synáček
@ 2022-07-04 10:53     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-04 10:53 UTC (permalink / raw)
  To: Jan Synáček; +Cc: 56336

Jan Synáček <jan.synacek@gmail.com> writes:

> Well, I know about one thing that might work well enough as an
> additional heuristic just for this case.
>
> It seems that if a command only outputs to stdout (and probably to
> stderr as well) and doesn't really ask for input, lsof -p <that async
> process> shows something like this:
> $ lsof -p 145475

[...]

> Note the /dev/tty in the output. I'm not sure, but I think this might
> be good enough.

It's not portable across operating systems, though.  (And the processes
may play shenanigans with detaching and spawning other processes that
then ask for a password (think xdg-open and friends), so it's not
reliable on Linux either.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:"
  2022-07-03 12:19     ` Lars Ingebrigtsen
@ 2022-08-02 11:02       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-08-02 11:02 UTC (permalink / raw)
  To: miha; +Cc: 56336, Jan Synáček

Lars Ingebrigtsen <larsi@gnus.org> writes:

>> Thanks. I think an equivalent change could be made for
>> eshell-watch-for-password-prompt and term-watch-for-password-prompt as
>> well.
>
> Are they used in contexts where this is meaningful?  I.e., used from
> commands like `M-&' that kill off the shell?

There wasn't any followup here in a month, so I don't think it's worth
tweaking this more unless anybody has an actual case where this bugs
out, and I'm therefore closing this bug report.






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-08-02 11:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 12:03 bug#56336: 28.1.90; [28.1] Emacs prompts for password when output from async command contains "password:" Jan Synáček
2022-07-02 12:28 ` Lars Ingebrigtsen
2022-07-03  7:53   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-03 12:19     ` Lars Ingebrigtsen
2022-08-02 11:02       ` Lars Ingebrigtsen
2022-07-03 16:54   ` Jan Synáček
2022-07-04 10:53     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).