diff options
author | 2020-03-28 17:43:12 +0100 | |
---|---|---|
committer | 2020-03-28 09:43:12 -0700 | |
commit | 5b3190a2e9b9f0b2d7e2973234c993b14a3e33fd (patch) | |
tree | 474a264644343e42c7c3d222697c73eba36f51e7 /projects/quickjs | |
parent | 25e9894f3f38b418e6ab3e26b3857f7666426b78 (diff) |
Fix behavior in quickjs fuzz target (#3543)
* Fix behavior in quickjs fuzz target
* Includes stdbool.h in quickjs fuzz target
* Right include
Diffstat (limited to 'projects/quickjs')
-rw-r--r-- | projects/quickjs/fuzz_compile.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/projects/quickjs/fuzz_compile.c b/projects/quickjs/fuzz_compile.c index 0dc47188..573a3f87 100644 --- a/projects/quickjs/fuzz_compile.c +++ b/projects/quickjs/fuzz_compile.c @@ -14,6 +14,7 @@ */ #include "quickjs-libc.h" +#include "cutils.h" #include <stdint.h> #include <stdio.h> @@ -71,10 +72,28 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; } obj = JS_ReadObject(ctx, bytecode, bytecode_size, JS_READ_OBJ_BYTECODE); - JS_FreeValue(ctx, obj); + if (JS_IsException(obj)) { + return 0; + } nbinterrupts = 0; - //this needs patching so as not to exit on JS exception - js_std_eval_binary(ctx, bytecode, bytecode_size, 0); + /* this is based on + * js_std_eval_binary(ctx, bytecode, bytecode_size, 0); + * modified so as not to exit on JS exception + */ + JSValue val; + if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) { + if (JS_ResolveModule(ctx, obj) < 0) { + JS_FreeValue(ctx, obj); + return 0; + } + js_module_set_import_meta(ctx, obj, FALSE, TRUE); + } + val = JS_EvalFunction(ctx, obj); + if (JS_IsException(val)) { + js_std_dump_error(ctx); + return 0; + } + JS_FreeValue(ctx, val); js_std_loop(ctx); js_free(ctx, bytecode); } |