Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v2

- name: Cache maven artifacts
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2

- name: Cache maven artifacts
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ripe/ipresource/Asn.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class Asn extends UniqueIpResource {
// unsigned long value.
private int intValue;

public Asn(BigInteger value) {
this(value.longValue());
public Asn(BigInteger value) {
this(value.longValueExact());
}

public Asn(long value) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/ripe/ipresource/IpRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public static IpRange range(IpAddress start, IpAddress end) {

public static IpRange prefix(IpAddress networkNumber, int prefixLength) {
Validate.notNull(networkNumber, "network number not null");
Validate.isTrue(prefixLength >= 0);
Validate.isTrue(prefixLength <= networkNumber.getType().getBitSize());
Validate.isTrue(prefixLength >= 0, "prefix length must be non-negative");
Validate.isTrue(prefixLength <= networkNumber.getType().getBitSize(),
"prefix " + prefixLength + " out of bounds (maximum " + networkNumber.getType().getBitSize() + ")");
return new IpRange(networkNumber, prefixLength);
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/java/net/ripe/ipresource/AsnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import static org.junit.Assert.*;

import java.math.BigInteger;

import org.junit.Test;

/**
Expand Down Expand Up @@ -80,6 +82,18 @@ public void shouldFailOnIllegalValue() {
Asn.parse("AS232442321412");
}

@Test(expected = IllegalArgumentException.class)
public void shouldFailOnVeryBigLong() {
new Asn(1 << 63L);
}

@Test(expected = ArithmeticException.class)
public void shouldFailOnWraparoundBigInteger() {
// BigInteger.longValue() keeps only the low 64 bits, so converting this value with longValue()
// would wrap around to 5, which is in range. Asn(BigInteger) must reject it regardless.
new Asn(BigInteger.ONE.shiftLeft(64).add(BigInteger.valueOf(5)));
Comment thread
lolepezy marked this conversation as resolved.
}

@Test
public void shouldParseDotNotatedAsNumber() {
assertEquals(new Asn(65536), Asn.parse("AS1.0"));
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/net/ripe/ipresource/IpRangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ public void shouldCheckPrefixLength_NonNegative() {
public void shouldCheckPrefixLength_NotGreatherThanAddressBitSize() {
IpRange.prefix(IpAddress.parse("127.0.0.0"), 34);
}

@Test(expected = IllegalArgumentException.class)
public void shouldCheckPrefixLength_NotGreatherThanAddressBitSize_v6() {
IpRange.prefix(IpAddress.parse("2001:67c:2e8:13:21e:c2ff:0:0"), 129);
}
}
Loading