Skip to content
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

Permit zone file strings upto AND including 255 characters in length. #284

Merged
merged 2 commits into from
Mar 21, 2024
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
17 changes: 15 additions & 2 deletions src/zonefile/inplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ impl<'a> EntryScanner<'a> {
// or an escape sequence.
while self.zonefile.buf.next_ascii_symbol()?.is_some() {
*write += 1;
if *write >= latest {
if *write > latest {
return Err(EntryError::bad_charstr());
}
}
Expand All @@ -930,7 +930,7 @@ impl<'a> EntryScanner<'a> {
Some(sym) => {
self.zonefile.buf.buf[*write] = sym.into_octet()?;
*write += 1;
if *write >= latest {
if *write > latest {
return Err(EntryError::bad_charstr());
}
}
Expand Down Expand Up @@ -1638,4 +1638,17 @@ mod test {
"../../test-data/zonefiles/unknown.yaml"
));
}

#[test]
fn test_chrstr_decoding() {
TestCase::test(include_str!("../../test-data/zonefiles/strlen.yaml"));
}

#[test]
#[should_panic(expected = "character string with more than 255 octets")]
fn test_chrstr_overlfow_decoding() {
TestCase::test(include_str!(
"../../test-data/zonefiles/stroverflow.yaml"
));
}
}
15 changes: 15 additions & 0 deletions test-data/zonefiles/strlen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
origin: example.com.
zonefile: |
254.short 3600 IN TXT "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"
255.max 3600 IN TXT "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
result:
- owner: 254.short.example.com.
class: IN
ttl: 3600
data: !Txt
- 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
- owner: 255.max.example.com.
class: IN
ttl: 3600
data: !Txt
- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
9 changes: 9 additions & 0 deletions test-data/zonefiles/stroverflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
origin: example.com.
zonefile: |
256.long 3600 IN TXT "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"
result:
- owner: 256.long.example.com.
class: IN
ttl: 3600
data: !Txt
- 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
Loading