Skip to content

Commit

Permalink
C Sharp stacktrace parsing (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
BMikh0 authored Mar 18, 2024
1 parent c040cea commit 064d0b7
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 8 deletions.
14 changes: 14 additions & 0 deletions casr/src/bin/casr-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ fn build_tree_report(
tree.collapse_item(row);
}

if !report.csharp_report.is_empty() {
row = tree
.insert_container_item("CSharpReport".to_string(), Placement::After, row)
.unwrap();
report.csharp_report.iter().for_each(|e| {
tree.insert_item(e.clone(), Placement::LastChild, row);
});
tree.collapse_item(row);
}

if !report.source.is_empty() {
row = tree
.insert_container_item("Source".to_string(), Placement::After, row)
Expand Down Expand Up @@ -655,6 +665,10 @@ fn build_slider_report(
select.add_item("JsReport", report.js_report.join("\n"));
}

if !report.csharp_report.is_empty() {
select.add_item("CSharpReport", report.csharp_report.join("\n"));
}

if !report.source.is_empty() {
select.add_item("Source", report.source.join("\n"));
}
Expand Down
13 changes: 11 additions & 2 deletions libcasr/fuzz/fuzz_targets/parse_stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use libcasr::{
java::JavaStacktrace,
python::PythonStacktrace,
js::JsStacktrace,
csharp::CSharpStacktrace,
stacktrace::{CrashLineExt, Filter, ParseStacktrace, Stacktrace},
};

Expand All @@ -18,8 +19,8 @@ fuzz_target!(|data: &[u8]| {
return;
}
let s = String::from_utf8_lossy(&data[1..]);
init_ignored_frames!("cpp", "rust", "python", "go", "java", "js");
match data[0] % 6 {
init_ignored_frames!("cpp", "rust", "python", "go", "java", "js", "csharp");
match data[0] % 7 {
0 => {
// Asan
if let Ok(raw) = AsanStacktrace::extract_stacktrace(&s) {
Expand Down Expand Up @@ -60,6 +61,14 @@ fuzz_target!(|data: &[u8]| {
}
}
}
5 => {
// C#
if let Ok(raw) = CSharpStacktrace::extract_stacktrace(&s) {
if let Ok(st) = CSharpStacktrace::parse_stacktrace(&raw) {
let _ = st.crash_line();
}
}
}
_ => {
// Gdb
if let Ok(raw) = GdbStacktrace::extract_stacktrace(&s) {
Expand Down
10 changes: 10 additions & 0 deletions libcasr/fuzz/init_corpus/csharp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Unhandled Exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at B..ctor () [0x00008] in /home/user/mono/src/2.cs:33
at A`1+<>c[T].<set_Q>b__1_1 () [0x00001] in /home/user/mono/src/2.cs:14
at A`1[T].h[Z] (System.Func`1[TResult] a) [0x00001] in /home/user/mono/src/2.cs:25
at A`1[T].<set_Q>g__g|1_0 (System.Int32[] arr) [0x00001] in /home/user/mono/src/2.cs:12
at A`1[T].set_Q (System.Int32 value) [0x00002] in /home/user/mono/src/2.cs:19
at Program+<>c.<Main>b__0_2 (System.Int32 i) [0x00000] in /home/user/mono/src/1.cs:8
at Program.<Main>g__f|0_0 (System.Func`2[T,TResult] d, System.Int32& l, System.Int32 m) [0x00021] in /home/user/mono/src/1.cs:9
at Program.Main () [0x00004] in /home/user/mono/src/1.cs:13
2 changes: 1 addition & 1 deletion libcasr/fuzz/init_corpus/gdb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
 #0 0x00000000005e3099 in xlnt::detail::compound_document::read_directory (this=0x7fffffffcee0) at /xlnt/source/detail/cryptography/compound_document.cpp:975
 #0 0x00000000005e3099 in xlnt::detail::compound_document::read_directory (this=0x7fffffffcee0) at /xlnt/source/detail/cryptography/compound_document.cpp:975
#1 0x00000000005e2956 in xlnt::detail::compound_document::compound_document (this=0x7fffffffcee0, in=...) at /xlnt/source/detail/cryptography/compound_document.cpp:517
#2 0x000000000048a45c in (anonymous namespace)::decrypt_xlsx (bytes=std::vector of length 18655, capacity 32768 = {...}, password=u\"VelvetSweatshop\") at /xlnt/source/detail/cryptography/xlsx_crypto_consumer.cpp:320
#3 0x000000000048a2d9 in xlnt::detail::decrypt_xlsx (data=std::vector of length 18655, capacity 32768 = {...}, password=) at /xlnt/source/detail/cryptography/xlsx_crypto_consumer.cpp:339
Expand Down
12 changes: 12 additions & 0 deletions libcasr/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_CPP: &[&str] = &[
r"^atheris::",
];

/// Regular expressions for с# functions to be ignored.
pub const STACK_FRAME_FUNCTION_IGNORE_REGEXES_CSHARP: &[&str] = &[
// TODO
r"^\(wrapper",
];

/// Regular expressions for paths to java files that should be ignored.
pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_JAVA: &[&str] = &[
// TODO
Expand Down Expand Up @@ -313,6 +319,12 @@ pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_CPP: &[&str] = &[
r".*asan_with_fuzzer\.so",
];

/// Regular expressions for paths to c# files that should be ignored.
pub const STACK_FRAME_FILEPATH_IGNORE_REGEXES_CSHARP: &[&str] = &[
// TODO
r"^[^.]$",
];

// Signal numbers
pub const SIGINFO_SIGILL: u32 = 4;
pub const SIGINFO_SIGTRAP: u32 = 5;
Expand Down
Loading

0 comments on commit 064d0b7

Please sign in to comment.