Skip to content

Commit

Permalink
QuickJS: disabling eval() and string normalize.
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Jul 2, 2024
1 parent 911cacd commit c773ebc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion external/njs_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -2811,7 +2811,7 @@ njs_engine_qjs_init(njs_engine_t *engine, njs_opts_t *opts)
return NJS_ERROR;
}

engine->u.qjs.ctx = qjs_new_context(engine->u.qjs.rt);
engine->u.qjs.ctx = qjs_new_context(engine->u.qjs.rt, 1);
if (engine->u.qjs.ctx == NULL) {
njs_stderror("JS_NewContext() failed\n");
return NJS_ERROR;
Expand Down
18 changes: 16 additions & 2 deletions src/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,30 @@


JSContext *
qjs_new_context(JSRuntime *rt)
qjs_new_context(JSRuntime *rt, _Bool eval)
{
JSContext *ctx;
qjs_module_t **module;

ctx = JS_NewContext(rt);
ctx = JS_NewContextRaw(rt);
if (ctx == NULL) {
return NULL;
}

JS_AddIntrinsicBaseObjects(ctx);
JS_AddIntrinsicDate(ctx);
JS_AddIntrinsicRegExp(ctx);
JS_AddIntrinsicJSON(ctx);
JS_AddIntrinsicProxy(ctx);
JS_AddIntrinsicMapSet(ctx);
JS_AddIntrinsicTypedArrays(ctx);
JS_AddIntrinsicPromise(ctx);
JS_AddIntrinsicBigInt(ctx);

if (eval) {
JS_AddIntrinsicEval(ctx);
}

for (module = qjs_modules; *module != NULL; module++) {
if ((*module)->init(ctx, (*module)->name) == NULL) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/qjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct {
} qjs_module_t;


JSContext *qjs_new_context(JSRuntime *rt);
JSContext *qjs_new_context(JSRuntime *rt, _Bool eval);


JSValue qjs_buffer_alloc(JSContext *ctx, size_t size);
Expand Down

0 comments on commit c773ebc

Please sign in to comment.