-
Notifications
You must be signed in to change notification settings - Fork 36
Casr-js #176
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
Merged
Merged
Casr-js #176
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
305f346
Add casr-js & modify casr-libfuzzer
PaDarochek 94a46a4
Find absolute path for tool in casr-js
PaDarochek a8e6633
Add tests for casr-js
PaDarochek 7da9005
Fix tests for casr-js
PaDarochek cfbc781
Update usage.md & tests
PaDarochek a5694cf
Update tests
PaDarochek 9612e6d
Update README
PaDarochek 3c6999e
Add tests for casr-libfuzzer & fixes
PaDarochek 7d4df55
Add usage example & update tests
PaDarochek 95bf723
Fix tests
PaDarochek 415b067
Fix test
PaDarochek 7b4acc3
Fix
PaDarochek 8fa5993
Fixes
PaDarochek e21996d
Fix
PaDarochek 5ce12e6
Add xml2js test
PaDarochek b7e3d61
Fixes
PaDarochek 59ea50c
Debugging CI test
PaDarochek 8ea2878
Fixes
PaDarochek af82750
Fix
PaDarochek 4b0276c
Debugging CI test
PaDarochek 514356f
Fix CI test
PaDarochek 74c731e
Fixes
PaDarochek 3f37b35
Fix
PaDarochek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,6 @@ Cargo.lock | |
| */Cargo.lock | ||
| */tests/tmp_tests_casr | ||
| *.swp | ||
| node_modules | ||
| */node_modules/* | ||
| .vscode | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| use casr::util; | ||
| use libcasr::{ | ||
| exception::Exception, init_ignored_frames, js::*, report::CrashReport, stacktrace::*, | ||
| }; | ||
|
|
||
| use anyhow::{bail, Result}; | ||
| use clap::{Arg, ArgAction, ArgGroup}; | ||
| use regex::Regex; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::Command; | ||
|
|
||
| fn main() -> Result<()> { | ||
| let matches = clap::Command::new("casr-js") | ||
| .version(clap::crate_version!()) | ||
| .about("Create CASR reports (.casrep) from JavaScript crash reports") | ||
| .term_width(90) | ||
| .arg( | ||
| Arg::new("output") | ||
| .short('o') | ||
| .long("output") | ||
| .action(ArgAction::Set) | ||
| .value_parser(clap::value_parser!(PathBuf)) | ||
| .value_name("REPORT") | ||
| .help( | ||
| "Path to save report. Path can be a directory, then report name is generated", | ||
| ), | ||
| ) | ||
| .arg( | ||
| Arg::new("stdout") | ||
| .action(ArgAction::SetTrue) | ||
| .long("stdout") | ||
| .help("Print CASR report to stdout"), | ||
| ) | ||
| .group( | ||
| ArgGroup::new("out") | ||
| .args(["stdout", "output"]) | ||
| .required(true), | ||
| ) | ||
| .arg( | ||
| Arg::new("stdin") | ||
| .long("stdin") | ||
| .action(ArgAction::Set) | ||
| .value_parser(clap::value_parser!(PathBuf)) | ||
| .value_name("FILE") | ||
| .help("Stdin file for program"), | ||
| ) | ||
| .arg( | ||
| Arg::new("timeout") | ||
| .short('t') | ||
| .long("timeout") | ||
| .action(ArgAction::Set) | ||
| .default_value("0") | ||
| .value_name("SECONDS") | ||
| .help("Timeout (in seconds) for target execution, 0 value means that timeout is disabled") | ||
| .value_parser(clap::value_parser!(u64).range(0..)) | ||
| ) | ||
| .arg( | ||
| Arg::new("ignore") | ||
| .long("ignore") | ||
| .action(ArgAction::Set) | ||
| .value_parser(clap::value_parser!(PathBuf)) | ||
| .value_name("FILE") | ||
| .help("File with regular expressions for functions and file paths that should be ignored"), | ||
| ) | ||
| .arg( | ||
| Arg::new("ARGS") | ||
| .action(ArgAction::Set) | ||
| .num_args(1..) | ||
| .last(true) | ||
| .help("Add \"-- <path> <arguments>\" to run"), | ||
| ) | ||
| .get_matches(); | ||
|
|
||
| init_ignored_frames!("js"); | ||
SweetVishnya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if let Some(path) = matches.get_one::<PathBuf>("ignore") { | ||
| util::add_custom_ignored_frames(path)?; | ||
| } | ||
| // Get program args. | ||
| let argv: Vec<&str> = if let Some(argvs) = matches.get_many::<String>("ARGS") { | ||
| argvs.map(|s| s.as_str()).collect() | ||
| } else { | ||
| bail!("Wrong arguments for starting program"); | ||
| }; | ||
|
|
||
| // Get stdin for target program. | ||
| let stdin_file = util::stdin_from_matches(&matches)?; | ||
|
|
||
| // Get timeout | ||
| let timeout = *matches.get_one::<u64>("timeout").unwrap(); | ||
|
|
||
| // Run program. | ||
| let mut js_cmd = Command::new(argv[0]); | ||
| if let Some(ref file) = stdin_file { | ||
| js_cmd.stdin(std::fs::File::open(file)?); | ||
| } | ||
| if argv.len() > 1 { | ||
| js_cmd.args(&argv[1..]); | ||
| } | ||
| let js_result = util::get_output(&mut js_cmd, timeout, true)?; | ||
|
|
||
| let js_stderr = String::from_utf8_lossy(&js_result.stderr); | ||
|
|
||
| // Create report. | ||
| let mut report = CrashReport::new(); | ||
| // Set executable path. | ||
| report.executable_path = argv[0].to_string(); | ||
| let mut path_to_tool = PathBuf::new(); | ||
| path_to_tool.push(argv[0]); | ||
| if argv.len() > 1 { | ||
| if let Some(fname) = Path::new(argv[0]).file_name() { | ||
SweetVishnya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let Ok(full_path_to_tool) = which::which(fname) else { | ||
| bail!("Could not get the full path of {}", argv[0]); | ||
| }; | ||
| path_to_tool = full_path_to_tool; | ||
| let fname = fname.to_string_lossy(); | ||
| if (fname == "node" || fname == "jsfuzz") && argv[1].ends_with(".js") { | ||
| report.executable_path = argv[1].to_string(); | ||
| } else if argv.len() > 2 | ||
| && fname == "npx" | ||
| && argv[1] == "jazzer" | ||
| && argv[2].ends_with(".js") | ||
| { | ||
| report.executable_path = argv[2].to_string(); | ||
| } | ||
| } | ||
| } | ||
| report.proc_cmdline = argv.join(" "); | ||
| let _ = report.add_os_info(); | ||
| let _ = report.add_proc_environ(); | ||
|
|
||
| // Get JS report. | ||
| let js_stderr_list: Vec<String> = js_stderr.split('\n').map(|l| l.to_string()).collect(); | ||
| let re = Regex::new(r"^(?:.*Error:(?:\s+.*)?|Thrown at:)$").unwrap(); | ||
| if let Some(start) = js_stderr_list.iter().position(|x| re.is_match(x)) { | ||
anfedotoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| report.js_report = js_stderr_list[start..].to_vec(); | ||
| report | ||
| .js_report | ||
| .retain(|x| !x.is_empty() && (x.trim().starts_with("at") || x.contains("Error:"))); | ||
| let report_str = report.js_report.join("\n"); | ||
| report.stacktrace = JsStacktrace::extract_stacktrace(&report_str)?; | ||
| if let Some(exception) = JsException::parse_exception(&report.js_report[0]) { | ||
| report.execution_class = exception; | ||
| } | ||
| } else { | ||
| // Call casr-san with absolute path to interpreter/fuzzer | ||
| let mut modified_argv = argv.clone(); | ||
| modified_argv[0] = path_to_tool.to_str().unwrap_or(argv[0]); | ||
| return util::call_casr_san(&matches, &modified_argv, "casr-js"); | ||
| } | ||
|
|
||
| if let Ok(crash_line) = JsStacktrace::parse_stacktrace(&report.stacktrace)?.crash_line() { | ||
| report.crashline = crash_line.to_string(); | ||
| if let CrashLine::Source(debug) = crash_line { | ||
| if let Some(sources) = CrashReport::sources(&debug) { | ||
| report.source = sources; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //Output report | ||
| util::output_report(&report, &matches, &argv) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "cflags": [ "-fexceptions -fsanitize=address,fuzzer-no-link -O0 -g -fPIC" ], | ||
| "cflags_cc": [ "-fexceptions -fsanitize=address,fuzzer-no-link -O0 -g -fPIC" ], | ||
| "include_dirs" : ["<!@(node -p \"require('node-addon-api').include\")"], | ||
| "target_name": "native", | ||
| "sources": [ "native.cpp" ], | ||
| 'defines': [ 'NAPI_CPP_EXCEPTIONS' ] | ||
| } | ||
| ] | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include <napi.h> | ||
| #include <stdio.h> | ||
|
|
||
| void foo(const Napi::CallbackInfo &info) | ||
| { | ||
| Napi::Env env = info.Env(); | ||
| uint8_t buf[] = {1, 2, 3}; | ||
| Napi::Buffer<uint8_t> arr = Napi::Buffer<uint8_t>::New(env, &buf[0], 3); | ||
| arr[5u] = 1; | ||
| printf("Number: %u\n", arr[5u]); | ||
| // throw Napi::String::New(env, "error in native lib"); | ||
| } | ||
|
|
||
| Napi::Object init(Napi::Env env, Napi::Object exports) | ||
| { | ||
| exports.Set(Napi::String::New(env, "foo"), Napi::Function::New(env, foo)); | ||
| return exports; | ||
| }; | ||
|
|
||
| NODE_API_MODULE(native, init); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| function bar() { | ||
| new Function(` | ||
| throw new Error('internal'); | ||
| `)(); | ||
| } | ||
|
|
||
| function foo() { | ||
| bar(); | ||
| } | ||
|
|
||
| function main() { | ||
| foo(); | ||
| } | ||
|
|
||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.