Skip to content

Commit 84b1f33

Browse files
committed
Add test to reproduce #56
1 parent faa90de commit 84b1f33

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: src/dns_parser/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use thiserror::Error;
44
#[derive(Debug, Error)]
55
#[allow(dead_code)]
66
pub enum Error {
7+
#[error("invalid compression pointer")]
8+
BadPointer,
79
#[error("packet is smaller than header size")]
810
HeaderTooShort,
911
#[error("packet is has incomplete data")]

Diff for: src/dns_parser/name.rs

+28
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,31 @@ impl<'a> PartialEq for Name<'a> {
186186
}
187187

188188
impl<'a> Eq for Name<'a> {}
189+
190+
#[cfg(test)]
191+
mod test {
192+
use super::Error;
193+
use super::Name;
194+
195+
#[test]
196+
fn parse_badpointer_same_offset() {
197+
// A buffer where an offset points to itself,
198+
// which is a bad compression pointer.
199+
let same_offset = vec![192, 2, 192, 2];
200+
let is_match = matches!(Name::scan(&same_offset, &same_offset),
201+
Err(Error::BadPointer));
202+
203+
assert!(is_match);
204+
}
205+
206+
#[test]
207+
fn parse_badpointer_forward_offset() {
208+
// A buffer where the offsets points back to each other which causes
209+
// infinite recursion if never checked, a bad compression pointer.
210+
let forwards_offset = vec![192, 2, 192, 4, 192, 2];
211+
let is_match = matches!(Name::scan(&forwards_offset, &forwards_offset),
212+
Err(Error::BadPointer));
213+
214+
assert!(is_match);
215+
}
216+
}

0 commit comments

Comments
 (0)