Skip to content

Infinite loop issue #33

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 2 commits into from
Mar 15, 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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "netflow_parser"
description = "Parser for Netflow Cisco V5, V7, V9, IPFIX"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
author = "[email protected]"
license = "MIT OR Apache-2.0"
Expand Down
3 changes: 3 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.2.1
* Fixed issue where no ipfix template fields can infinite loop.

# 0.2.0
* Clippy updates for 1.76
* Removed dbg! macros for now for performance reason until we have a better solution.
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported |
| ------- | ------------------ |
| 0.2.1 | :white_check_mark: |
| 0.2.0 | :white_check_mark: |
| 0.1.9 | :white_check_mark: |
| 0.1.8 | :white_check_mark: |
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ mod tests {
assert_yaml_snapshot!(parser.parse_bytes(&packet));
}

#[test]
fn it_parses_ipfix_with_no_template_fields_raises_error() {
let packet = [
0, 10, 0, 26, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 2, 0, 10, 0, 8, 0, 0, 1, 1,
];
let template = IPFixTemplate {
field_count: 2,
template_id: 258,
fields: vec![],
};
let mut parser = NetflowParser::default();
parser.ipfix_parser.templates.insert(258, template);
assert_yaml_snapshot!(parser.parse_bytes(&packet));
}

#[test]
fn it_parses_ipfix_options_template() {
let packet = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
source: src/lib.rs
expression: parser.parse_bytes(&packet)
---
- Error:
error_message: "Could not parse v10_set: Parsing Error: Error { input: [0, 8, 0, 0, 1, 1], code: Fail }"
bytes:
- 0
- 10
- 0
- 26
- 0
- 0
- 0
- 1
- 0
- 0
- 0
- 1
- 0
- 0
- 0
- 0
- 1
- 2
- 0
- 10
- 0
- 8
- 0
- 0
- 1
- 1

5 changes: 5 additions & 0 deletions src/variable_versions/ipfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ fn parse_fields<T: CommonTemplateFields>(
return Err(NomErr::Error(NomError::new(i, ErrorKind::Fail)));
}
};
// If no fields there are no fields to parse
if template.get_fields().is_empty() {
// dbg!("Template without fields!");
return Err(NomErr::Error(NomError::new(i, ErrorKind::Fail)));
};
let mut fields = vec![];
let mut remaining = i;
while !remaining.is_empty() {
Expand Down