Unverified Commit b06cccff by Enkelmann Committed by GitHub

Sort generated CWE warnings by address (#221)

parent 681b50df
...@@ -39,7 +39,7 @@ use crate::{ ...@@ -39,7 +39,7 @@ use crate::{
use petgraph::graph::NodeIndex; use petgraph::graph::NodeIndex;
use petgraph::visit::IntoNodeReferences; use petgraph::visit::IntoNodeReferences;
use petgraph::Direction; use petgraph::Direction;
use std::collections::HashMap; use std::collections::{BTreeMap, HashMap};
mod context; mod context;
pub mod object; pub mod object;
...@@ -496,9 +496,9 @@ pub fn run<'a>( ...@@ -496,9 +496,9 @@ pub fn run<'a>(
fn collect_all_logs( fn collect_all_logs(
receiver: crossbeam_channel::Receiver<LogThreadMsg>, receiver: crossbeam_channel::Receiver<LogThreadMsg>,
) -> (Vec<LogMessage>, Vec<CweWarning>) { ) -> (Vec<LogMessage>, Vec<CweWarning>) {
let mut logs_with_address = HashMap::new(); let mut logs_with_address = BTreeMap::new();
let mut general_logs = Vec::new(); let mut general_logs = Vec::new();
let mut collected_cwes = HashMap::new(); let mut collected_cwes = BTreeMap::new();
while let Ok(log_thread_msg) = receiver.recv() { while let Ok(log_thread_msg) = receiver.recv() {
match log_thread_msg { match log_thread_msg {
...@@ -523,7 +523,10 @@ fn collect_all_logs( ...@@ -523,7 +523,10 @@ fn collect_all_logs(
.cloned() .cloned()
.chain(general_logs.into_iter()) .chain(general_logs.into_iter())
.collect(); .collect();
let cwes = collected_cwes.drain().map(|(_key, value)| value).collect(); let cwes = collected_cwes
.into_iter()
.map(|(_key, value)| value)
.collect();
(logs, cwes) (logs, cwes)
} }
......
...@@ -107,6 +107,7 @@ pub fn check_cwe( ...@@ -107,6 +107,7 @@ pub fn check_cwe(
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
......
...@@ -116,5 +116,6 @@ pub fn check_cwe( ...@@ -116,5 +116,6 @@ pub fn check_cwe(
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -175,5 +175,6 @@ pub fn check_cwe( ...@@ -175,5 +175,6 @@ pub fn check_cwe(
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -70,5 +70,6 @@ pub fn check_cwe( ...@@ -70,5 +70,6 @@ pub fn check_cwe(
cwe_warnings.push(generate_cwe_warning(secure_initializer_func, rand_func)); cwe_warnings.push(generate_cwe_warning(secure_initializer_func, rand_func));
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -119,5 +119,6 @@ pub fn check_cwe( ...@@ -119,5 +119,6 @@ pub fn check_cwe(
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -96,5 +96,6 @@ pub fn check_cwe( ...@@ -96,5 +96,6 @@ pub fn check_cwe(
} }
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -132,5 +132,6 @@ pub fn check_cwe( ...@@ -132,5 +132,6 @@ pub fn check_cwe(
} }
} }
} }
cwe_warnings.sort();
(Vec::new(), cwe_warnings) (Vec::new(), cwe_warnings)
} }
...@@ -45,7 +45,7 @@ use crate::prelude::*; ...@@ -45,7 +45,7 @@ use crate::prelude::*;
use crate::utils::log::{CweWarning, LogMessage}; use crate::utils::log::{CweWarning, LogMessage};
use crate::CweModule; use crate::CweModule;
use petgraph::visit::EdgeRef; use petgraph::visit::EdgeRef;
use std::collections::HashMap; use std::collections::BTreeMap;
mod state; mod state;
use state::*; use state::*;
...@@ -123,7 +123,7 @@ pub fn check_cwe( ...@@ -123,7 +123,7 @@ pub fn check_cwe(
} }
} }
let mut cwe_warnings = HashMap::new(); let mut cwe_warnings = BTreeMap::new();
for cwe in cwe_receiver.try_iter() { for cwe in cwe_receiver.try_iter() {
match &cwe.addresses[..] { match &cwe.addresses[..] {
[taint_source_address, ..] => cwe_warnings.insert(taint_source_address.clone(), cwe), [taint_source_address, ..] => cwe_warnings.insert(taint_source_address.clone(), cwe),
......
...@@ -141,5 +141,6 @@ pub fn check_cwe( ...@@ -141,5 +141,6 @@ pub fn check_cwe(
} }
} }
cwes.sort();
(log_messages, cwes) (log_messages, cwes)
} }
...@@ -89,6 +89,7 @@ pub fn generate_cwe_warnings<'a>( ...@@ -89,6 +89,7 @@ pub fn generate_cwe_warnings<'a>(
cwe_warnings.push(cwe_warning); cwe_warnings.push(cwe_warning);
} }
cwe_warnings.sort();
cwe_warnings cwe_warnings
} }
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
//! - Missing Taints due to lost track of pointer targets //! - Missing Taints due to lost track of pointer targets
//! - Non tracked function parameters cause incomplete taints that could miss possible dangerous inputs //! - Non tracked function parameters cause incomplete taints that could miss possible dangerous inputs
use std::collections::{HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use crate::{ use crate::{
analysis::{ analysis::{
...@@ -161,7 +161,7 @@ pub fn check_cwe( ...@@ -161,7 +161,7 @@ pub fn check_cwe(
} }
} }
let mut cwe_warnings = HashMap::new(); let mut cwe_warnings = BTreeMap::new();
for cwe in cwe_receiver.try_iter() { for cwe in cwe_receiver.try_iter() {
match &cwe.addresses[..] { match &cwe.addresses[..] {
[taint_source_address, ..] => cwe_warnings.insert(taint_source_address.clone(), cwe), [taint_source_address, ..] => cwe_warnings.insert(taint_source_address.clone(), cwe),
......
...@@ -82,5 +82,6 @@ pub fn check_cwe( ...@@ -82,5 +82,6 @@ pub fn check_cwe(
.iter() .iter()
.for_each(|sub| warnings.append(&mut handle_sub(sub, symbol))); .for_each(|sub| warnings.append(&mut handle_sub(sub, symbol)));
} }
warnings.sort();
(vec![], warnings) (vec![], warnings)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment