Skip to content

issues 25, 26, 27 #31

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

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 0.2.0
* Clippy updates for 1.76
* Removed dbg! macros for now for performance reason until we have a better solution.
* Fixed issue where bad IPFIX options template causes panic.

# 0.1.9
* Fixed bug with flow counts in V9.
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@ mod tests {
assert_yaml_snapshot!(NetflowParser::default().parse_bytes(&packet));
}

#[test]
fn it_doesnt_panic_with_invalid_options_ipfix_template() {
let packet = [
0, 10, 0, 44, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 3, 0, 28, 1, 4, 0, 13, 0, 1,
128, 123, 0, 4, 0, 0, 0, 2, 0, 41, 0, 2, 0, 42, 0, 2, 0, 0,
];
NetflowParser::default().parse_bytes(&packet);
}

#[test]
fn it_parses_ipfix_data_cached_template() {
let packet = [
Expand Down
8 changes: 4 additions & 4 deletions src/variable_versions/ipfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub struct TemplateField {
/// Parses options template
fn parse_options_template(i: &[u8], length: u16) -> IResult<&[u8], OptionsTemplate> {
let (remaining, taken) = take(length.checked_sub(4).unwrap_or(length))(i)?;
let (_, option_template) = OptionsTemplate::parse(taken).unwrap();
let (_, option_template) = OptionsTemplate::parse(taken)?;
Ok((remaining, option_template))
}

Expand Down Expand Up @@ -216,7 +216,7 @@ fn parse_fields<T: CommonTemplateFields>(
let template = match template {
Some(t) => t,
None => {
dbg!("Could not fetch any v10 templates!");
// dbg!("Could not fetch any v10 templates!");
return Err(NomErr::Error(NomError::new(i, ErrorKind::Fail)));
}
};
Expand Down Expand Up @@ -333,12 +333,12 @@ impl NetflowByteParserVariable for IPFixParser {

let mut total_left = v10_header.length as usize;

dbg!("remaining: {}", remaining);
// dbg!("remaining: {}", remaining);

while total_left != 0 {
let (left_remaining, v10_set) = Set::parse(remaining, self)
.map_err(|e| format!("Could not parse v10_set: {e}"))?;
dbg!("left remaining: {}", left_remaining);
// dbg!("left remaining: {}", left_remaining);
remaining = left_remaining;
let parsed = total_left
.checked_sub(remaining.len())
Expand Down
6 changes: 3 additions & 3 deletions src/variable_versions/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ fn parse_fields(
let template = match template {
Some(t) => t,
None => {
dbg!("Could not fetch any v10 templates!");
// dbg!("Could not fetch any v9 templates!");
return Err(NomErr::Error(NomError::new(i, ErrorKind::Fail)));
}
};
Expand Down Expand Up @@ -446,7 +446,7 @@ fn parse_options_data_fields(
templates: HashMap<u16, OptionsTemplate>,
) -> IResult<&[u8], Vec<OptionDataField>> {
let template = templates.get(&flow_set_id).ok_or_else(|| {
dbg!("Could not fetch any v9 options templates!");
// dbg!("Could not fetch any v9 options templates!");
NomErr::Error(NomError::new(i, ErrorKind::Fail))
})?;
let mut fields = vec![];
Expand All @@ -465,7 +465,7 @@ fn parse_scope_data_fields(
templates: HashMap<u16, OptionsTemplate>,
) -> IResult<&[u8], Vec<ScopeDataField>> {
let template = templates.get(&flow_set_id).ok_or_else(|| {
dbg!("Could not fetch any v9 options templates!");
// dbg!("Could not fetch any v9 options templates!");
NomErr::Error(NomError::new(i, ErrorKind::Fail))
})?;
let mut fields = vec![];
Expand Down