Client: Don't log error on datagram dissector fail (ticket #1915),

let the client do the logging.
Throw early if data too short
This commit is contained in:
zzz
2017-01-17 15:34:38 +00:00
parent a36083ab18
commit 60c93f1e1c

View File

@ -31,6 +31,7 @@ import net.i2p.util.Log;
public final class I2PDatagramDissector { public final class I2PDatagramDissector {
private static final int DGRAM_BUFSIZE = 32768; private static final int DGRAM_BUFSIZE = 32768;
private static final int MIN_DGRAM_SIZE = 387 + 40;
private final DSAEngine dsaEng = DSAEngine.getInstance(); private final DSAEngine dsaEng = DSAEngine.getInstance();
private final SHA256Generator hashGen = SHA256Generator.getInstance(); private final SHA256Generator hashGen = SHA256Generator.getInstance();
@ -68,9 +69,12 @@ public final class I2PDatagramDissector {
* @throws DataFormatException If there's an error in the datagram format * @throws DataFormatException If there's an error in the datagram format
*/ */
public void loadI2PDatagram(byte[] dgram) throws DataFormatException { public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
// set invalid(very important!) // set invalid(very important!)
this.valid = false; this.valid = false;
if (dgram.length < MIN_DGRAM_SIZE)
throw new DataFormatException("repliable datagram too small: " + dgram.length);
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
try { try {
// read destination // read destination
@ -96,8 +100,9 @@ public final class I2PDatagramDissector {
rxHash = null; rxHash = null;
} }
} catch (IOException e) { } catch (IOException e) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class); // let the application do the logging
log.error("Error loading datagram", e); //Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class);
//log.error("Error loading datagram", e);
throw new DataFormatException("Error loading datagram", e); throw new DataFormatException("Error loading datagram", e);
//} catch(AssertionError e) { //} catch(AssertionError e) {
// Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class); // Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class);