2020-05-09 09:23:26 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2022-01-16 09:16:04 -03:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2020-05-09 09:23:26 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-09 09:23:26 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-04-08 05:40:02 -03:00
|
|
|
#include <AK/StringView.h>
|
2023-08-08 02:10:39 -03:00
|
|
|
#include <LibJS/Bytecode/Interpreter.h>
|
2021-01-03 12:01:36 -03:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2022-01-16 09:16:04 -03:00
|
|
|
#include <LibJS/Script.h>
|
2020-04-08 05:40:02 -03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
2020-04-08 05:40:02 -03:00
|
|
|
{
|
2023-11-03 14:49:54 -03:00
|
|
|
AK::set_debug_enabled(false);
|
2022-04-01 14:58:27 -03:00
|
|
|
auto js = StringView(static_cast<unsigned char const*>(data), size);
|
2023-03-17 15:59:56 -03:00
|
|
|
// FIXME: https://github.com/SerenityOS/serenity/issues/17899
|
|
|
|
|
if (!Utf8View(js).validate())
|
|
|
|
|
return 0;
|
2023-03-17 11:44:47 -03:00
|
|
|
auto vm = MUST(JS::VM::create());
|
2023-08-08 02:10:39 -03:00
|
|
|
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
|
|
|
|
|
auto& realm = *root_execution_context->realm;
|
|
|
|
|
auto parse_result = JS::Script::parse(js, realm);
|
2022-01-16 09:16:04 -03:00
|
|
|
if (!parse_result.is_error())
|
2023-08-08 02:10:39 -03:00
|
|
|
(void)vm->bytecode_interpreter().run(parse_result.value());
|
2022-01-16 09:16:04 -03:00
|
|
|
|
2020-04-08 05:40:02 -03:00
|
|
|
return 0;
|
|
|
|
|
}
|