From a438722eed63db1aa9b9581d8c98949bbbf05961 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sat, 16 Apr 2016 16:10:56 +0000 Subject: [PATCH] TunnelId: Add max value check --- core/java/src/net/i2p/data/TunnelId.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/java/src/net/i2p/data/TunnelId.java b/core/java/src/net/i2p/data/TunnelId.java index 2188614ca5..6c06093486 100644 --- a/core/java/src/net/i2p/data/TunnelId.java +++ b/core/java/src/net/i2p/data/TunnelId.java @@ -27,7 +27,7 @@ import java.io.OutputStream; public class TunnelId extends DataStructureImpl { private long _tunnelId; - public static final long MAX_ID_VALUE = (1l<<32l)-2l; + public static final long MAX_ID_VALUE = (1L << 32) - 2L; public TunnelId() { _tunnelId = -1; @@ -35,22 +35,22 @@ public class TunnelId extends DataStructureImpl { /** * @param id 1 to 0xffffffff - * @throws IllegalArgumentException if less than or equal to zero + * @throws IllegalArgumentException if less than or equal to zero or greater than max value */ public TunnelId(long id) { - if (id <= 0) throw new IllegalArgumentException("wtf, tunnelId " + id); - _tunnelId = id; + setTunnelId(id); } public long getTunnelId() { return _tunnelId; } /** * @param id 1 to 0xffffffff - * @throws IllegalArgumentException if less than or equal to zero + * @throws IllegalArgumentException if less than or equal to zero or greater than max value */ public void setTunnelId(long id) { + if (id <= 0 || id > MAX_ID_VALUE) + throw new IllegalArgumentException("bad id " + id); _tunnelId = id; - if (id <= 0) throw new IllegalArgumentException("wtf, tunnelId " + id); } public void readBytes(InputStream in) throws DataFormatException, IOException { -- GitLab