diff --git a/casr/src/bin/casr-afl.rs b/casr/src/bin/casr-afl.rs index 2c0f158b..4ff9e9cd 100644 --- a/casr/src/bin/casr-afl.rs +++ b/casr/src/bin/casr-afl.rs @@ -165,7 +165,9 @@ fn main() -> Result<()> { match util::symbols_list(Path::new(target)) { Ok(list) => { if list.contains("__asan") { - crash_info.casr_tool = util::get_path("casr-san")?.clone() + crash_info + .casr_tool + .clone_from(&(util::get_path("casr-san")?)) } } Err(e) => { diff --git a/casr/src/bin/casr-core.rs b/casr/src/bin/casr-core.rs index 4854970b..e6b65b2f 100644 --- a/casr/src/bin/casr-core.rs +++ b/casr/src/bin/casr-core.rs @@ -431,7 +431,7 @@ fn analyze_coredump( }; if report.proc_cmdline.is_empty() { - report.proc_cmdline = run_line.clone(); + report.proc_cmdline.clone_from(&run_line) } } } diff --git a/casr/tests/casr_tests/csharp/test_casr_csharp_native/native.cpp b/casr/tests/casr_tests/csharp/test_casr_csharp_native/native.cpp new file mode 100644 index 00000000..201bad9f --- /dev/null +++ b/casr/tests/casr_tests/csharp/test_casr_csharp_native/native.cpp @@ -0,0 +1,7 @@ +#include + +extern "C" void seg(int len) +{ + int a[10]; + a[len] = -1; +} diff --git a/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.cs b/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.cs new file mode 100644 index 00000000..2f626725 --- /dev/null +++ b/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.cs @@ -0,0 +1,19 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; + +public class Program +{ + public static void Seg() + { + [DllImport("native.so", EntryPoint="seg")] + static extern void seg(int size); + + seg(100000000); + } + + public static void Main(string[] args) + { + Seg(); + } +} diff --git a/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.csproj b/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.csproj new file mode 100644 index 00000000..c1368a7f --- /dev/null +++ b/casr/tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + disable + + + diff --git a/casr/tests/tests.rs b/casr/tests/tests.rs index fb08fd4d..61b4f68d 100644 --- a/casr/tests/tests.rs +++ b/casr/tests/tests.rs @@ -4748,7 +4748,7 @@ fn test_casr_js() { }; let output = Command::new(*EXE_CASR_JS.read().unwrap()) - .args(["--stdout", "--", &node_path.to_str().unwrap(), &test_path]) + .args(["--stdout", "--", (node_path.to_str().unwrap()), &test_path]) .output() .expect("failed to start casr-js"); @@ -4813,7 +4813,7 @@ fn test_casr_js_jsfuzz() { .args([ "--stdout", "--", - &jsfuzz_path.to_str().unwrap(), + (jsfuzz_path.to_str().unwrap()), &paths[0], &paths[1], ]) @@ -4881,7 +4881,7 @@ fn test_casr_js_jazzer() { .args([ "--stdout", "--", - &npx_path.to_str().unwrap(), + (npx_path.to_str().unwrap()), "jazzer", &paths[0], &paths[1], @@ -5689,7 +5689,7 @@ fn test_casr_csharp() { .args([ "--stdout", "--", - &dotnet_path.to_str().unwrap(), + (dotnet_path.to_str().unwrap()), "run", "--project", &paths[4], @@ -5724,6 +5724,73 @@ fn test_casr_csharp() { } } +#[test] +#[cfg(target_arch = "x86_64")] +fn test_casr_csharp_native() { + let paths = [ + abs_path("tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.cs"), + abs_path("tests/casr_tests/csharp/test_casr_csharp_native/test_casr_csharp_native.csproj"), + abs_path("tests/casr_tests/csharp/test_casr_csharp_native/native.cpp"), + abs_path("tests/tmp_tests_casr/test_casr_csharp_native"), + abs_path("tests/tmp_tests_casr/test_casr_csharp_native/test_casr_csharp_native.cs"), + abs_path("tests/tmp_tests_casr/test_casr_csharp_native/test_casr_csharp_native.csproj"), + abs_path("tests/tmp_tests_casr/test_casr_csharp_native/native.so"), + ]; + let _ = std::fs::create_dir_all(&paths[3]); + let _ = fs::copy(&paths[0], &paths[4]); + let _ = fs::copy(&paths[1], &paths[5]); + let Ok(dotnet_path) = which::which("dotnet") else { + panic!("No dotnet is found."); + }; + + let _ = Command::new("clang++") + .args([&paths[2], "-g", "-fPIC", "-shared", "-o", &paths[6]]) + .output() + .expect("failed to compile .so library"); + + let _ = Command::new("dotnet") + .args(["build", &paths[5]]) + .output() + .expect("failed to build test"); + + let output = Command::new(*EXE_CASR_CSHARP.read().unwrap()) + .args([ + "--stdout", + "--", + (dotnet_path.to_str().unwrap()), + format!("{}/bin/Debug/net8.0/test_casr_csharp_native.dll", &paths[3]).as_str(), + ]) + .env("LD_LIBRARY_PATH", &paths[3]) + .output() + .expect("failed to start casr-csharp"); + + assert!( + output.status.success(), + "Stdout {}.\n Stderr: {}", + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr) + ); + + let report: Result = serde_json::from_slice(&output.stdout); + if let Ok(report) = report { + let severity_type = report["CrashSeverity"]["Type"].as_str().unwrap(); + let severity_desc = report["CrashSeverity"]["ShortDescription"] + .as_str() + .unwrap() + .to_string(); + + assert_eq!(19, report["Stacktrace"].as_array().unwrap().iter().count()); + assert_eq!(severity_type, "NOT_EXPLOITABLE"); + assert_eq!(severity_desc, "AccessViolation"); + assert!(report["CrashLine"] + .as_str() + .unwrap() + .contains("native.cpp:6")); + } else { + panic!("Couldn't parse json report file."); + } +} + #[test] #[cfg(target_arch = "x86_64")] fn test_casr_afl_csharp() { @@ -5864,7 +5931,7 @@ fn test_casr_afl_csharp_ignore_cmd() { "-o", &paths[1], "--", - &dotnet_path.to_str().unwrap(), + (dotnet_path.to_str().unwrap()), "run", "--no-build", "--project",