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 src/main/java/org/xbill/DNS/DNSInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void clearActive() {

/** Returns the position of the end of the current active region. */
public int saveActive() {
return limit - offset;
return byteBuffer.limit() - offset;
}

/**
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/xbill/DNS/DNSInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -84,6 +86,19 @@ void setUp() {
}
}

static class DNSInputByteBufferLimitOffsetTest extends DNSInputBase {
@BeforeEach
void setUp() throws IOException {
m_raw = new byte[] {0, 1, 2, 3, 4, 5, (byte) 255, (byte) 255, (byte) 255, (byte) 255};
// create a new byte array with a prefix and a suffix to be ignored
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(42);
out.write(m_raw);
out.write(47);
m_di = new DNSInput(ByteBuffer.wrap(out.toByteArray(), 1, 10));
}
}

@Test
void initial_state() {
assertEquals(0, m_di.current());
Expand Down Expand Up @@ -319,4 +334,28 @@ void readCountedSting() throws WireParseException {
assertEquals(3, m_di.current());
assertEquals(2, out[0]);
}

@Test
void setActive_recursive() throws WireParseException {
int outer = m_di.saveActive();
m_di.setActive(3);

assertEquals(0x00, m_di.readU8());
assertEquals(2, m_di.remaining());

int inner = m_di.saveActive();

m_di.setActive(1);
assertArrayEquals(new byte[] {0x01}, m_di.readByteArray());

m_di.restoreActive(inner);

assertArrayEquals(new byte[] {0x02}, m_di.readByteArray());
assertEquals(0, m_di.remaining());

m_di.restoreActive(outer);

assertEquals(0x03, m_di.readU8());
assertEquals(6, m_di.remaining());
}
}
21 changes: 21 additions & 0 deletions src/test/java/org/xbill/DNS/OPTRecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.xbill.DNS.utils.base16;

class OPTRecordTest {

Expand Down Expand Up @@ -47,6 +50,24 @@ void rdataFromString() {
assertTrue(thrown.getMessage().contains("no text format defined for OPT"));
}

@Test
void rdataFromWire() throws IOException {
byte[] buf = base16.fromString("000029100000000000000C000A00084531D089BA80C6EB");
OPTRecord record = (OPTRecord) OPTRecord.fromWire(new DNSInput(buf), Section.ADDITIONAL);
assertEquals(
Collections.singletonList(new CookieOption(base16.fromString("4531D089BA80C6EB"))),
record.getOptions());
}

@Test
void rdataFromWire_nullPadded() throws IOException {
byte[] buf = base16.fromString("000029100000000000000C000A00084531D089BA80C6EB00");
OPTRecord record = (OPTRecord) OPTRecord.fromWire(new DNSInput(buf), Section.ADDITIONAL);
assertEquals(
Collections.singletonList(new CookieOption(base16.fromString("4531D089BA80C6EB"))),
record.getOptions());
}

private void assertNotEqual(final OPTRecord optRecordOne, final OPTRecord optRecordTwo) {
assertFalse(optRecordOne.equals(optRecordTwo));
assertFalse(optRecordTwo.equals(optRecordOne));
Expand Down