Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
headshog committed May 23, 2024
1 parent 158c425 commit 63507e3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 7 deletions.
4 changes: 3 additions & 1 deletion casr/src/bin/casr-afl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion casr/src/bin/casr-core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

extern "C" void seg(int len)
{
int a[10];
a[len] = -1;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

</Project>
77 changes: 72 additions & 5 deletions casr/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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],
])
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -5689,7 +5689,7 @@ fn test_casr_csharp() {
.args([
"--stdout",
"--",
&dotnet_path.to_str().unwrap(),
(dotnet_path.to_str().unwrap()),
"run",
"--project",
&paths[4],
Expand Down Expand Up @@ -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<Value, _> = 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() {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 63507e3

Please sign in to comment.