Skip to content

Commit

Permalink
Check domain length
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <[email protected]>
  • Loading branch information
sticnarf committed Sep 5, 2019
1 parent 9c266e7 commit e435b5e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ impl<'a> IntoTargetAddr<'a> for (&'a str, u16) {
}

// Treat as domain name
let len = self.0.as_bytes().len();
if len > 255 {
if self.0.len() > 255 {
return Err(Error::InvalidTargetAddress("overlong domain"));
}
// TODO: Should we validate the domain format here?
Expand All @@ -193,6 +192,9 @@ impl<'a> IntoTargetAddr<'a> for &'a str {
let domain = parts_iter
.next()
.ok_or(Error::InvalidTargetAddress("invalid address format"))?;
if domain.len() > 255 {
return Err(Error::InvalidTargetAddress("overlong domain"));
}
Ok(TargetAddr::Domain(domain.into(), port))
}
}
Expand All @@ -213,6 +215,9 @@ impl IntoTargetAddr<'static> for String {
.next()
.ok_or(Error::InvalidTargetAddress("invalid address format"))?
.len();
if domain_len > 255 {
return Err(Error::InvalidTargetAddress("overlong domain"));
}
self.truncate(domain_len);
Ok(TargetAddr::Domain(self.into(), port))
}
Expand Down

0 comments on commit e435b5e

Please sign in to comment.