forked from I2P_Developers/i2p.i2p
Router: Validate tunnel ID in requests
Fix max ID
This commit is contained in:
@ -27,7 +27,7 @@ import java.io.OutputStream;
|
||||
public class TunnelId extends DataStructureImpl {
|
||||
private long _tunnelId;
|
||||
|
||||
public static final long MAX_ID_VALUE = (1L << 32) - 2L;
|
||||
public static final long MAX_ID_VALUE = 0xffffffffL;
|
||||
|
||||
public TunnelId() {
|
||||
_tunnelId = -1;
|
||||
|
@ -396,7 +396,7 @@ public class TunnelDispatcher implements Service {
|
||||
long rv;
|
||||
TunnelId tid;
|
||||
do {
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
|
||||
tid = new TunnelId(rv);
|
||||
} while (_outboundGateways.containsKey(tid));
|
||||
return rv;
|
||||
@ -413,7 +413,7 @@ public class TunnelDispatcher implements Service {
|
||||
long rv;
|
||||
TunnelId tid;
|
||||
do {
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
|
||||
tid = new TunnelId(rv);
|
||||
} while (_participants.containsKey(tid));
|
||||
return rv;
|
||||
@ -430,7 +430,7 @@ public class TunnelDispatcher implements Service {
|
||||
long rv;
|
||||
TunnelId tid;
|
||||
do {
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
|
||||
rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
|
||||
tid = new TunnelId(rv);
|
||||
} while (_inboundGateways.containsKey(tid));
|
||||
return rv;
|
||||
|
@ -668,6 +668,16 @@ class BuildHandler implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ourId <= 0 || ourId > TunnelId.MAX_ID_VALUE ||
|
||||
nextId <= 0 || nextId > TunnelId.MAX_ID_VALUE) {
|
||||
_context.statManager().addRateData("tunnel.rejectHostile", 1);
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Dropping build request, bad tunnel ID: " + req);
|
||||
if (from != null)
|
||||
_context.commSystem().mayDisconnect(from);
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop checks
|
||||
if ((!isOutEnd) && _context.routerHash().equals(nextPeer)) {
|
||||
_context.statManager().addRateData("tunnel.rejectHostile", 1);
|
||||
|
@ -95,7 +95,7 @@ abstract class BuildRequestor {
|
||||
else if (isIB && i == len - 1)
|
||||
id = ctx.tunnelDispatcher().getNewIBEPID();
|
||||
else
|
||||
id = 1 + ctx.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
|
||||
id = 1 + ctx.random().nextLong(TunnelId.MAX_ID_VALUE);
|
||||
cfg.getConfig(i).setReceiveTunnelId(DataHelper.toLong(4, id));
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ public class FragmentTest {
|
||||
_context.random().nextBytes(toRouter.getData());
|
||||
}
|
||||
if (includeTunnel)
|
||||
toTunnel = new TunnelId(_context.random().nextLong(TunnelId.MAX_ID_VALUE));
|
||||
toTunnel = new TunnelId(1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE));
|
||||
return new PendingGatewayMessage(m, toRouter, toTunnel);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user