jsch icon indicating copy to clipboard operation
jsch copied to clipboard

Remote Port Forwardings are mixed, although it's remote server is different from each other.

Open parkjunhong opened this issue 5 years ago • 0 comments
trafficstars

I found a bug that Remote Port Forwardings are mixed, although it's remote server is different from each other.

A method that provides Local Port Forwarding checks a Session instance.

PortWatcher.java
static String[] getPortForwarding(Session session){
  java.util.Vector foo=new java.util.Vector();
 
  synchronized(pool){
    for(int i=0; i<pool.size(); i++){
      PortWatcher p=(PortWatcher)(pool.elementAt(i));
      if(p.session==session){
        foo.addElement(p.lport+":"+p.host+":"+p.rport);
      }
    }
  }
 
  String[] bar=new String[foo.size()];
  for(int i=0; i<foo.size(); i++){
    bar[i]=(String)(foo.elementAt(i));
  }
  return bar;
}

But a method that provides Remote Port Forwardings DO NOT CHECK a Session instance.

ChannelForwardedTCPIP.java
static String[] getPortForwarding(Session session){
  Vector foo = new Vector();
 
  synchronized(pool){
    for(int i=0; i<pool.size(); i++){
      Config config = (Config)(pool.elementAt(i));
      if(config instanceof ConfigDaemon)
        foo.addElement(config.allocated_rport+":"+config.target+":");
      else
        foo.addElement(config.allocated_rport+":"+config.target+":"+((ConfigLHost)config).lport);
    }
  }
 
  String[] bar=new String[foo.size()];
  for(int i=0; i<foo.size(); i++){
    bar[i]=(String)(foo.elementAt(i));
  }
  return bar;
}

parkjunhong avatar May 20 '20 04:05 parkjunhong