Subject: bug#27009: 25.1; Tramp stuck on wrong host

From: "Devon Sean McCullough" <[email-masked]>
Date: Sun, 21 May 2017 05:12:07 -0500

Tramp connects to the wrong host -- the user may not notice, leading to
devastating damage.

To replicate this bug, have two different systems serve SSH on different
ports of the same IP address,
e.g., In VBox, map local host ports 11111 and 22222 respectively to two
different guest systems:
VirtualBox VM > Devices > Network > Network Settings ... > Adapter 1 >
  Attached to: NAT
  Advanced > Port Forwarding >
    Host Port: 11111 for system one, 22222 for system two
    Guest Port: 22

bash$ Open -n -a /Applications/Emacs.app --args -Q --eval '
(message "Emacs %s tramp bug %s" ; t = bug, nil = ok
	 emacs-version
	 (let ((one "/scp:127.0.0.1#11111:")
	       (two "/scp:127.0.0.1#22222:"))
	   (delete-other-windows)
	   (dired one)
	   (revert-buffer)
	   (split-window)
	   (other-window 1)
	   (dired two)
	   (revert-buffer)
	   (apply (function string=)
		  (mapcar (lambda (w)
			    (with-current-buffer (window-buffer w)
			      (buffer-substring (save-excursion
						  (goto-char (point-min))
						  (forward-line 1)
						  (point))
						(point-max))))
			  (window-list-1)))))'

		Peace
			--Devon

P.S. (tramp-cleanup-all-connections) ; fails to fix it but can switch
which host is wrong.

In GNU Emacs 25.1.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version
10.9.5 (Build 13F1911))
 of 2016-09-21 built on builder10-9.porkrind.org
Windowing system distributor 'Apple', version 10.3.1404
Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES

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

Major mode: Dired by name

Minor modes in effect:
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Tramp: Opening connection for 127.0.0.1#11111 using scp...
Tramp: Sending command ‘exec ssh  -p 11111 -o ControlMaster=auto -o
ControlPath='tramp.%C' -o ControlPersist=no -e none 127.0.0.1’
Tramp: Waiting for prompts from remote shell...done
Tramp: Found remote shell prompt on ‘127.0.0.1’
Tramp: Opening connection for 127.0.0.1#11111 using scp...done
ls does not support --dired; see ‘dired-use-ls-dired’ for more details.
Emacs 25.1.1 tramp bug t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rfc822 mml mml-sec epg
epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils
tramp-cache tramp-sh tramp tramp-compat auth-source cl-seq eieio
byte-opt bytecomp byte-compile cl-extra cconv eieio-core cl-macs gv
gnus-util mm-util help-fns help-mode easymenu cl-loaddefs pcase cl-lib
mail-prsvr password-cache tramp-loaddefs trampver shell pcomplete comint
ansi-color ring format-spec advice dired time-date mule-util tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
ns-win ucs-normalize term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame 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 charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 216764 9018)
 (symbols 48 22062 0)
 (miscs 40 59 298)
 (strings 32 24033 6626)
 (string-bytes 1 768617)
 (vectors 16 36983)
 (vector-slots 8 706708 7377)
 (floats 8 283 52)
 (intervals 56 539 0)
 (buffers 976 20))