Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote port forwarding, dynamic port allocation fails w. BufferException: underflow #236

Closed
anderserik opened this issue Mar 16, 2016 · 2 comments
Milestone

Comments

@anderserik
Copy link

java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
sshj version: 0.15.0
OpenSSH version: SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7

--- Connection establishment ---
then:

int localPort = 9999;
InetSocketAddress socketAddress = new InetSocketAddress(LOCALHOST, localPort);
RemotePortForwarder remotePortForwarder = sshClient.getRemotePortForwarder();
remotePortForwarder.bind(new Forward(0), new SocketForwardingConnectListener(socketAddress));

Fails with BufferException: underflow

See trace:

10:22:37.345 {main} INFO  c.e.nsta.utils.console.SSHConsole - Succesfully connected to 10.64.77.30:22
10:22:37.348 {main} DEBUG n.s.sshj.connection.ConnectionImpl - Attaching opener for `forwarded-tcpip` channels: net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder@76639310
10:22:37.350 {main} DEBUG n.s.sshj.connection.ConnectionImpl - Making global request for `tcpip-forward`
10:22:37.351 {main} TRACE net.schmizz.sshj.transport.Encoder - Encoding packet #10: 50 00 00 00 0d 74 63 70 69 70 2d 66 6f 72 77 61 72 64 01 00 00 00 00 00 00 00 00
10:22:37.351 {main} DEBUG net.schmizz.concurrent.Promise - Awaiting <<global req for tcpip-forward>>
10:22:37.353 {reader} TRACE net.schmizz.sshj.transport.Decoder - Received packet #14: 51 00 00 a1 4d
10:22:37.354 {reader} TRACE n.s.sshj.transport.TransportImpl - Received packet REQUEST_SUCCESS
10:22:37.355 {reader} DEBUG net.schmizz.concurrent.Promise - Setting <<global req for tcpip-forward>> to `Buffer [rpos=6, wpos=10, size=1024]`
Exception in thread "main" net.schmizz.sshj.connection.ConnectionException: Underflow
    at net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder.bind(RemotePortForwarder.java:175)
    at com.ericsson.nsta.utils.console.SSHConsole.createRemoteTunnel(SSHConsole.java:405)
    at SSHPortForwardDemo.main(SSHPortForwardDemo.java:22)
Caused by: net.schmizz.sshj.common.Buffer$BufferException: Underflow
    at net.schmizz.sshj.common.Buffer.ensureAvailable(Buffer.java:131)
    at net.schmizz.sshj.common.Buffer.readUInt32(Buffer.java:296)
    at net.schmizz.sshj.common.Buffer.readUInt32AsInt(Buffer.java:291)
    at net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder.bind(RemotePortForwarder.java:173)
    ... 2 more
@hierynomus
Copy link
Owner

Hi,

Thanks for the bug report, I've managed to reproduce this in a testcase in commit ca49ca3.

@hierynomus
Copy link
Owner

Ok! I've found it, it was a race condition (debugging didn't trigger the exception) 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants