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

java.lang.ArrayIndexOutOfBoundsException: 1024 #29

Open
nicoulaj opened this issue Feb 15, 2016 · 5 comments
Open

java.lang.ArrayIndexOutOfBoundsException: 1024 #29

nicoulaj opened this issue Feb 15, 2016 · 5 comments

Comments

@nicoulaj
Copy link

I'm getting this error when trying to use this lib on a shared server with quite a lot of users:

java.lang.ArrayIndexOutOfBoundsException: 1024
    at com.jcraft.jsch.agentproxy.Buffer.getByte(Buffer.java:142)
    at com.jcraft.jsch.agentproxy.Buffer.getShort(Buffer.java:138)
    at com.jcraft.jsch.agentproxy.Buffer.getInt(Buffer.java:123)
    at com.jcraft.jsch.agentproxy.Buffer.getString(Buffer.java:181)
    at com.jcraft.jsch.agentproxy.AgentProxy.getIdentities(AgentProxy.java:112)
    at com.jcraft.jsch.agentproxy.RemoteIdentityRepository.getIdentities(RemoteIdentityRepository.java:47)
    at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:39)
    at com.jcraft.jsch.Session.connect(Session.java:463)
    at com.jcraft.jsch.Session.connect(Session.java:183)

If this can help, in AgentProxy.getIdentities(), I get:

  • rcode=0
  • count=267
  • it crashes at i=127

The factory is NCUSocketFactory.
The version of netcat is 1.84 (on CentOS 6.X).

@booiiing
Copy link

booiiing commented Jul 6, 2016

The root cause is line 71 in AgentProxy, where the buffer is initialized with a size of 1024.
A temporary fix would be using a bigger constant here. However, since this project seems to be unmaintained, I am unsure whether it would get a release :(

@kekbur
Copy link

kekbur commented Aug 16, 2016

For me the exception does not occur when using Pageant 0.61. It does occur with later versions.

@rafaroca
Copy link

rafaroca commented Nov 7, 2016

I believe that there is a bug in AgentProxy.java. buffer.insertLength(); in line 88 inserts the length as int. The buffer.getByte() in line 100 would read the first of the four bytes of this int.

The same goes for all the other methods in this class. I did not test this, but I guess this could fix the issue:

diff --git a/jsch-agent-proxy-core/src/main/java/com/jcraft/jsch/agentproxy/AgentProxy.java b/jsch-agent-proxy-core/src/main/java/com/jcraft/jsch/agentproxy/AgentProxy.java
index 8834150..bb84788 100644
--- a/jsch-agent-proxy-core/src/main/java/com/jcraft/jsch/agentproxy/AgentProxy.java
+++ b/jsch-agent-proxy-core/src/main/java/com/jcraft/jsch/agentproxy/AgentProxy.java
@@ -97,11 +97,11 @@ public class AgentProxy {
       return identities;
     }

+    int count = buffer.getInt();
     int rcode = buffer.getByte();

     check_reply(rcode);
 //System.out.println(rcode == code2);
-    int count = buffer.getInt();
 //System.out.println(count);

     identities = new Identity[count];

@nicoulaj
Copy link
Author

Probably not, @ymnk last activity on Github goes back to November 2014.

@lemmy
Copy link

lemmy commented Mar 22, 2019

At least on Linux, AIOOBE is a red herring! The root cause isn't incorrect code as suspected by @rafaroca. Instead, it seems to be the combination of the underlying Connector reading an invalid value for the environment variable SSH_AUTH_SOCK and AgentProxy improperly handling this error and thus throwing a misleading ArrayIndexOutOfBoundsException.

You can convince yourself that the order in which rcode and count are read from buffer are correct by cross-checking the spec and two alternative implementations.

A sensible fix for the underlying SSH_AUTH_SOCK problem would be a check if process p (see below) is alive. If SSH_AUTH_SOCK is incorrect, p has terminated with a non-null exit value:

lemmy added a commit to tlaplus/tlaplus that referenced this issue Mar 22, 2019
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

5 participants