From e72c698ec5d1778177fbbc7341da4814a3963bc6 Mon Sep 17 00:00:00 2001 From: qpxdesign Date: Mon, 27 May 2024 18:18:05 -0400 Subject: [PATCH] fixed issue with non-complaint lines --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/utils/parse_line.rs | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30c5112..a188901 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -701,7 +701,7 @@ dependencies = [ [[package]] name = "ngxav" -version = "0.6.2" +version = "0.6.3" dependencies = [ "atty", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 177d2fb..6efd0cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ workspace = { members = [ "tests","tests/obfuscate_access_log_ips"] } [package] name = "ngxav" -version = "0.6.2" +version = "0.6.3" edition = "2021" license = "MIT" description = "Search through NGINX logs with advanced filters and support for displaying analytics about your selected log entries" diff --git a/src/utils/parse_line.rs b/src/utils/parse_line.rs index 7f37656..e6ce852 100644 --- a/src/utils/parse_line.rs +++ b/src/utils/parse_line.rs @@ -9,6 +9,20 @@ lazy_static! { pub fn parse_line(line: &str) -> crate::structs::LineParseResult::LineParseResult { let matches: Vec<&str> = R.find_iter(line).map(|mat| mat.as_str()).collect(); let mut fields = line.split(" ").collect::>(); + if fields.len() < 12 || matches.len() < 4 { + return crate::structs::LineParseResult::LineParseResult { + ip_address: "-", + time: "".to_string(), + host: "", + referer: "", + request: "", + status: "", + body_bytes_sent: 0, + request_time: 0, + user_agent: "", + full_text: line, + }; + } return crate::structs::LineParseResult::LineParseResult { ip_address: fields[0], time: fields[3].replace("[", "") + " " + &fields[4].replace("]", ""),