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

C Sharp stacktrace parsing #186

Merged
merged 11 commits into from
Mar 18, 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
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 @@
tree.collapse_item(row);
}

if !report.csharp_report.is_empty() {
row = tree
.insert_container_item("CSharpReport".to_string(), Placement::After, row)

Check warning on line 474 in casr/src/bin/casr-cli.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cli.rs#L472-L474

Added lines #L472 - L474 were not covered by tests
.unwrap();
report.csharp_report.iter().for_each(|e| {
tree.insert_item(e.clone(), Placement::LastChild, row);
});
tree.collapse_item(row);

Check warning on line 479 in casr/src/bin/casr-cli.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cli.rs#L476-L479

Added lines #L476 - L479 were not covered by tests
}

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

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

Check warning on line 669 in casr/src/bin/casr-cli.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cli.rs#L668-L669

Added lines #L668 - L669 were not covered by tests
}

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
Loading