Skip to content
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.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "corgea"
version = "1.7.2"
version = "1.8.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
62 changes: 62 additions & 0 deletions src/scanners/parsers/coverity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use super::{ParseResult, ScanParser};
use crate::log::debug;
use quick_xml::events::Event;
use quick_xml::Reader;

pub struct CoverityParser;

impl ScanParser for CoverityParser {
fn detect(&self, input: &str) -> bool {
input.contains("xmlns:cov=\"http://coverity.com\"")
}

fn parse(&self, input: &str) -> Option<ParseResult> {
debug("Detected coverity schema");

let mut paths = Vec::new();
let mut reader = Reader::from_str(input);
let mut buf = Vec::new();

loop {
match reader.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e)) => {
let is_merged_defect = e.name().as_ref() == b"cov:mergedDefect"
|| e.name().as_ref() == b"mergedDefect";
if is_merged_defect {
for attr in e.attributes() {
if let Ok(attr) = attr {
if attr.key.as_ref() == b"file" {
if let Ok(file_path) = std::str::from_utf8(attr.value.as_ref())
{
let clean_path = file_path
.trim_start_matches('/')
.trim_start_matches('\\');
if !clean_path.is_empty() {
paths.push(clean_path.to_string());
}
}
}
}
}
}
}
Ok(Event::Eof) => break,
Err(e) => {
eprintln!("Error parsing XML: {}", e);
return None;
}
_ => {}
}
buf.clear();
}

Some(ParseResult {
paths,
scanner: "coverity".to_string(),
})
}

fn scanner_name(&self) -> &str {
"coverity"
}
}
16 changes: 8 additions & 8 deletions src/scanners/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub struct ParseResult {

pub trait ScanParser {
fn detect(&self, input: &str) -> bool;

fn parse(&self, input: &str) -> Option<ParseResult>;

#[allow(dead_code)]
fn scanner_name(&self) -> &str;
}
Expand All @@ -27,16 +27,17 @@ impl ScanParserFactory {
Box::new(checkmarx::CheckmarxCliParser),
Box::new(checkmarx::CheckmarxWebParser),
Box::new(checkmarx::CheckmarxXmlParser),
Box::new(coverity::CoverityParser),
];

Self { parsers }
}

#[allow(dead_code)]
pub fn find_parser(&self, input: &str) -> Option<&Box<dyn ScanParser>> {
self.parsers.iter().find(|parser| parser.detect(input))
}

pub fn parse_scan_data(&self, input: &str) -> Result<ParseResult, String> {
for parser in &self.parsers {
if parser.detect(input) {
Expand All @@ -46,7 +47,7 @@ impl ScanParserFactory {
}
}
}

crate::log::debug("Couldn't detect what kind of report this is.");
Err("Unsupported scan report format. Please check if your scanner is supported. Supported formats: JSON (Semgrep, SARIF, Checkmarx), XML (Checkmarx).".to_string())
}
Expand All @@ -55,5 +56,4 @@ impl ScanParserFactory {
pub mod semgrep;
pub mod sarif;
pub mod checkmarx;


pub mod coverity;
Loading