8000 Fix Name constructor failing with max length relative name and root origin by MMauro94 · Pull Request #289 · dnsjava/dnsjava · GitHub
[go: up one dir, main page]

Skip to content

Fix Name constructor failing with max length relative name and root origin #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/main/java/org/xbill/DNS/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public Name(String s, Name origin) throws TextParseException {
appendFromString(s, label, pos);
}
if (origin != null && !absolute) {
absolute = origin.isAbsolute();
appendFromString(s, origin.name, origin.labels);
}
// A relative name that is MAXNAME octets long is a strange and wonderful thing.
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/org/xbill/DNS/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,55 @@ void ctor_max_length_abs() throws TextParseException {
assertEquals(255, n.length());
}

@Test
void ctor_max_length_rel_with_root_origin() throws TextParseException {
// relative name with three 63-char labels and a 61-char label with Name.root as origin
Name n =
new Name(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
Name.root);
assertTrue(n.isAbsolute());
assertFalse(n.isWild());
assertEquals(5, n.labels());
assertEquals(255, n.length());
}

@Test
void ctor_max_length_rel_with_abs_origin() throws TextParseException {
// relative name with three 63-char labels and a 52-char label with 9-char absolute name as
// origin
Name n =
new Name(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddd",
Name.fromString("absolute."));
assertTrue(n.isAbsolute());
assertFalse(n.isWild());
assertEquals(6, n.labels());
assertEquals(255, n.length());
}

@Test
void ctor_too_long_rel_with_rel_origin() throws TextParseException {
// relative name with three 63-char labels and a 53-char label with an 8-char relative origin
assertThrows(
TextParseException.class,
() ->
new Name(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddd",
new Name("relative")));
}

@Test
void ctor_too_long_rel_with_abs_origin() {
// relative name with three 63-char labels and a 53-char label with a 9-char absolute origin
assertThrows(
TextParseException.class,
() ->
new Name(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddd",
new Name("absolute.")));
}

@Test
void ctor_escaped() throws TextParseException {
Name n = new Name("ab\\123cd");
Expand Down
0