diff --git a/src/zonefile/inplace.rs b/src/zonefile/inplace.rs index c108f3a9..cc1d0843 100644 --- a/src/zonefile/inplace.rs +++ b/src/zonefile/inplace.rs @@ -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()); } } @@ -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()); } } @@ -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" + )); + } } diff --git a/test-data/zonefiles/strlen.yaml b/test-data/zonefiles/strlen.yaml new file mode 100644 index 00000000..c4d0bdc6 --- /dev/null +++ b/test-data/zonefiles/strlen.yaml @@ -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 diff --git a/test-data/zonefiles/stroverflow.yaml b/test-data/zonefiles/stroverflow.yaml new file mode 100644 index 00000000..c1399374 --- /dev/null +++ b/test-data/zonefiles/stroverflow.yaml @@ -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