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

Ensure that workers in fuzzers can create their own context #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions fuzz/fuzz_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,35 @@ void reset_nbinterrupts() {
nbinterrupts = 0;
}

JSContext *JS_NewCustomContext(JSRuntime *rt)
{
JSContext *ctx = JS_NewContext(rt);
if (!ctx)
return NULL;

JS_AddIntrinsicBigFloat(ctx);
JS_AddIntrinsicBigDecimal(ctx);
JS_AddIntrinsicOperators(ctx);
JS_EnableBignumExt(ctx, 1);

js_init_module_std(ctx, "std");
js_init_module_os(ctx, "os");
return ctx;
}

void test_one_input_init(JSRuntime *rt, JSContext *ctx) {
// 64 Mo
JS_SetMemoryLimit(rt, 0x4000000);
// 64 Kb
JS_SetMaxStackSize(rt, 0x10000);

JS_AddIntrinsicBigFloat(ctx);
JS_AddIntrinsicBigDecimal(ctx);
JS_AddIntrinsicOperators(ctx);
JS_EnableBignumExt(ctx, 1);
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
JS_SetInterruptHandler(JS_GetRuntime(ctx), interrupt_handler, NULL);
js_std_set_worker_new_context_func(JS_NewCustomContext);
js_std_add_helpers(ctx, 0, NULL);

// Load os and std
js_std_init_handlers(rt);
js_init_module_std(ctx, "std");
js_init_module_os(ctx, "os");
const char *str = "import * as std from 'std';\n"
"import * as os from 'os';\n"
"globalThis.std = std;\n"
Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@

static int nbinterrupts = 0;

JSContext *JS_NewCustomContext(JSRuntime *rt);
void reset_nbinterrupts();
void test_one_input_init(JSRuntime *rt, JSContext *ctx);
2 changes: 1 addition & 1 deletion fuzz/fuzz_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;

JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JSContext *ctx = JS_NewCustomContext(rt);
test_one_input_init(rt, ctx);

uint8_t *null_terminated_data = malloc(size + 1);
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;

JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);
JSContext *ctx = JS_NewCustomContext(rt);
test_one_input_init(rt, ctx);

uint8_t *null_terminated_data = malloc(size + 1);
Expand Down