Skip to content

Commit

Permalink
Add tests for casr-js
Browse files Browse the repository at this point in the history
  • Loading branch information
PaDarochek committed Nov 8, 2023
1 parent 94a46a4 commit 56f3e7b
Show file tree
Hide file tree
Showing 13 changed files with 654 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ jobs:
- name: Run tests
run: |
sudo apt update && sudo apt install -y gdb pip curl python3.10-dev llvm \
openjdk-17-jdk
openjdk-17-jdk ca-certificates gnupg
pip3 install atheris
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
export NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt update && sudo apt install -y nodejs
npm install -g jsfuzz
npm install --save-dev @jazzer.js/core
curl https://sh.rustup.rs -o rustup.sh && chmod +x rustup.sh && \
./rustup.sh -y && rm rustup.sh
rustup install nightly
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ jobs:
- name: Install Dependences
run: |
sudo apt update && sudo apt install -y gdb pip curl python3.10-dev llvm \
openjdk-17-jdk
openjdk-17-jdk ca-certificates gnupg
pip3 install atheris
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
export NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt update && sudo apt install -y nodejs
npm install -g jsfuzz
npm install --save-dev @jazzer.js/core
curl https://sh.rustup.rs -o rustup.sh && chmod +x rustup.sh && \
./rustup.sh -y && rm rustup.sh
rustup install nightly
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Cargo.lock
*.swp
node_modules
*/node_modules/*
.vscode
12 changes: 12 additions & 0 deletions casr/tests/casr_tests/js/binding.gyp
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 -I/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/ -lclang_rt.fuzzer-x86_64" ],
"cflags_cc": [ "-fexceptions -fsanitize=address,fuzzer-no-link -O0 -g -fPIC -I/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux/ -lclang_rt.fuzzer-x86_64" ],
"include_dirs" : ["<!@(node -p \"require('node-addon-api').include\")"],
"target_name": "native",
"sources": [ "native.cpp" ],
'defines': [ 'NAPI_CPP_EXCEPTIONS' ]
}
]
}
1 change: 1 addition & 0 deletions casr/tests/casr_tests/js/crash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
20 changes: 20 additions & 0 deletions casr/tests/casr_tests/js/native.cpp
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);
15 changes: 15 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js.js
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()
18 changes: 18 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js_jazzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function bar() {
new Function(`
throw new Error('internal');
`)();
}

function foo() {
bar();
}

function fuzz(data) {
foo();
}

module.exports.fuzz = function (data /*: Buffer */) {
const fuzzerData = data.toString();
fuzz(fuzzerData);
};
19 changes: 19 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js_jsfuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function bar() {
new Function(`
throw new Error('internal');
`)();
}

function foo() {
bar();
}

function fuzz(data) {
foo();
}

module.exports = {
fuzz
};

fuzz(process.argv[1]);
5 changes: 5 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js_native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const native_lib = require('bindings')('native')

native_lib.foo();
10 changes: 10 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js_native_jazzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const native_lib = require('bindings')('native')

function fuzz(data) {
native_lib.foo();
}

module.exports.fuzz = function (data /*: Buffer */) {
const fuzzerData = data.toString();
fuzz(fuzzerData);
};
11 changes: 11 additions & 0 deletions casr/tests/casr_tests/js/test_casr_js_native_jsfuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const native_lib = require('bindings')('native')

function fuzz(data) {
native_lib.foo();
}

module.exports = {
fuzz
};

fuzz(process.argv[1]);
Loading

0 comments on commit 56f3e7b

Please sign in to comment.