Bug 2200

Summary: ssh -W causes "getsockname failed: Bad file descriptor" errors
Product: Portable OpenSSH Reporter: Colin Watson <cjwatson>
Component: sshAssignee: Damien Miller <djm>
Status: CLOSED FIXED    
Severity: normal CC: djm, dtucker
Priority: P5    
Version: 6.5p1   
Hardware: All   
OS: Linux   
URL: http://bugs.debian.org/738693
Bug Depends on:    
Bug Blocks: 2188    
Attachments:
Description Flags
Skip get_sock_port call for c->sock==-1 dtucker: ok+

Description Colin Watson 2014-02-12 22:22:57 AEDT
Marco d'Itri reports in http://bugs.debian.org/738693 that "ssh -W" has started causing "getsockname failed: Bad file descriptor" errors; these are new in 6.5p1 and reported via error().  I think this was triggered by the new calls to get_sock_port from port_open_helper in https://anongit.mindrot.org/openssh.git/commit/?id=4def184; gdb shows that c->sock is -1 here.

Full -vvv output in the Debian bug; relevant-looking excerpt:

debug3: ssh_init_stdio_forwarding: server2.example.net:22
debug1: channel_connect_stdio_fwd server2.example.net:22
debug1: channel 0: new [stdio-forward]
debug2: fd 4 setting O_NONBLOCK
debug3: fd 5 is O_NONBLOCK
getsockname failed: Bad file descriptor
debug1: getpeername failed: Bad file descriptor

It looks like it still works fine, but the extra non-debug error is annoying.
Comment 1 Damien Miller 2014-02-13 09:02:22 AEDT
Created attachment 2407 [details]
Skip get_sock_port call for c->sock==-1

Thanks for the detailed report as always. This should fix it.
Comment 2 Colin Watson 2014-02-15 13:36:29 AEDT
Thanks, that indeed seems to solve the problem here.
Comment 3 Damien Miller 2014-02-16 10:05:50 AEDT
applied - thanks.
Comment 4 Damien Miller 2014-10-08 08:00:56 AEDT
Close all bugs left open from 6.6 and 6.7 releases.