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

NSEC3 salt strings should only be accepted if within the salt size limit. #431

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 34 additions & 4 deletions src/rdata/nsec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: EmptyBuilder,
{
type Err = base16::DecodeError;
type Err = Nsec3SaltFromStrError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s == "-" {
Expand All @@ -927,7 +927,11 @@ where
})
} else {
base16::decode(s)
.map(|octets| unsafe { Self::from_octets_unchecked(octets) })
.map_err(Nsec3SaltFromStrError::DecodeError)
.and_then(|octets| {
Self::from_octets(octets)
.map_err(Nsec3SaltFromStrError::Nsec3SaltError)
})
}
}
}
Expand Down Expand Up @@ -1143,6 +1147,26 @@ where
}
}

//------------ Nsec3SaltFromStrError -----------------------------------------

/// An error happened while parsing an NSEC3 salt from a string.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Nsec3SaltFromStrError {
DecodeError(base16::DecodeError),
Nsec3SaltError(Nsec3SaltError),
}

//--- Display

impl fmt::Display for Nsec3SaltFromStrError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Nsec3SaltFromStrError::DecodeError(err) => err.fmt(f),
Nsec3SaltFromStrError::Nsec3SaltError(err) => err.fmt(f),
}
}
}

//------------ OwnerHash -----------------------------------------------------

/// The hash over the next owner name.
Expand Down Expand Up @@ -1567,7 +1591,10 @@ mod test {
Nsec3::scan,
&rdata,
);
assert_eq!(&format!("{}", rdata.display_zonefile(false)), "1 10 11 626172 CPNMU A SRV");
assert_eq!(
&format!("{}", rdata.display_zonefile(false)),
"1 10 11 626172 CPNMU A SRV"
);
}

#[test]
Expand All @@ -1591,7 +1618,10 @@ mod test {
Nsec3::scan,
&rdata,
);
assert_eq!(&format!("{}", rdata.display_zonefile(false)), "1 10 11 - CPNMU A SRV");
assert_eq!(
&format!("{}", rdata.display_zonefile(false)),
"1 10 11 - CPNMU A SRV"
);
}

#[test]
Expand Down