Browse Source

Catch attribute overflow errors (#26)

master
RJ Rybarczyk 4 years ago
committed by GitHub
parent
commit
dc53cfc194
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/as_path_parser.rs
  2. 5
      src/error.rs

12
src/as_path_parser.rs

@ -93,12 +93,16 @@ impl<'buffer> AsPathParser<'buffer> {
let asn_path = self.parse_as_path();
if asn_attr_position_end != self.next {
let leftover_attr_count = asn_attr_position_end - self.next;
for _ in 0..leftover_attr_count {
self.advance()?;
let leftover_attr_count = asn_attr_position_end.checked_sub(self.next);
match leftover_attr_count {
Some(count) => {
for _ in 0..count {
self.advance()?;
}
}
None => println!("{}", Error::AttributeOverflow),
}
}
asn_path
} else {
for _ in 0..attribute_length {

5
src/error.rs

@ -26,6 +26,7 @@ pub enum Error {
UnexpectedEndOfBuffer,
MultipleAsPaths,
NoAsPathInAttributePath,
AttributeOverflow,
}
impl Display for Error {
@ -63,6 +64,10 @@ impl Display for Error {
f,
"Expected one AS_PATH attribute in BGP Attribute Path, found multiple."
),
AttributeOverflow => write!(
f,
"Overflow encountered during AS parsing. Ignoring invalid attribute."
),
}
}
}

Loading…
Cancel
Save