Changeset 7433eeb for router


Ignore:
Timestamp:
Mar 7, 2018 6:06:46 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c5b6a4e
Parents:
ceac733
Message:

Router: Validate tunnel ID in requests
Fix max ID

Location:
router/java
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java

    rceac733 r7433eeb  
    397397        TunnelId tid;
    398398        do {
    399             rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
     399            rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
    400400            tid = new TunnelId(rv);
    401401        } while (_outboundGateways.containsKey(tid));
     
    414414        TunnelId tid;
    415415        do {
    416             rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
     416            rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
    417417            tid = new TunnelId(rv);
    418418        } while (_participants.containsKey(tid));
     
    431431        TunnelId tid;
    432432        do {
    433             rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
     433            rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
    434434            tid = new TunnelId(rv);
    435435        } while (_inboundGateways.containsKey(tid));
  • router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java

    rceac733 r7433eeb  
    664664            _context.statManager().addRateData("tunnel.rejectHostile", 1);
    665665            _log.error("Dropping build request, IBGW+OBEP: " + req);
     666            if (from != null)
     667                _context.commSystem().mayDisconnect(from);
     668            return;
     669        }
     670
     671        if (ourId <= 0 || ourId > TunnelId.MAX_ID_VALUE ||
     672            nextId <= 0 || nextId > TunnelId.MAX_ID_VALUE) {
     673            _context.statManager().addRateData("tunnel.rejectHostile", 1);
     674            if (_log.shouldWarn())
     675                _log.warn("Dropping build request, bad tunnel ID: " + req);
    666676            if (from != null)
    667677                _context.commSystem().mayDisconnect(from);
  • router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java

    rceac733 r7433eeb  
    9696                    id = ctx.tunnelDispatcher().getNewIBEPID();
    9797                else
    98                     id = 1 + ctx.random().nextLong(TunnelId.MAX_ID_VALUE - 1);
     98                    id = 1 + ctx.random().nextLong(TunnelId.MAX_ID_VALUE);
    9999                cfg.getConfig(i).setReceiveTunnelId(DataHelper.toLong(4, id));
    100100            }
  • router/java/test/junit/net/i2p/router/tunnel/FragmentTest.java

    rceac733 r7433eeb  
    162162        }
    163163        if (includeTunnel)
    164             toTunnel = new TunnelId(_context.random().nextLong(TunnelId.MAX_ID_VALUE));
     164            toTunnel = new TunnelId(1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE));
    165165        return new PendingGatewayMessage(m, toRouter, toTunnel);
    166166    }
Note: See TracChangeset for help on using the changeset viewer.