Open nicoulaj opened 8 years ago
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 :(
For me the exception does not occur when using Pageant 0.61. It does occur with later versions.
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];
Probably not, @ymnk last activity on Github goes back to November 2014.
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: https://github.com/ymnk/jsch-agent-proxy/blob/12c3d64fc2b0a4fd37659369edfdee26e48954e2/jsch-agent-proxy-usocket-nc/src/main/java/com/jcraft/jsch/agentproxy/usocket/NCUSocketFactory.java#L115
I'm getting this error when trying to use this lib on a shared server with quite a lot of users:
If this can help, in
AgentProxy.getIdentities()
, I get:The factory is
NCUSocketFactory
. The version of netcat is 1.84 (on CentOS 6.X).