From 1b260ab1f8deac83db52d04a0e8e27ef5a5e44b8 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 17 Mar 2023 12:54:27 -0400 Subject: [PATCH] Meta: Move global VM creation to fuzzer "global" structure Turns out LLVMFuzzerTestOneInput may be called more than once per process. --- Meta/Lagom/Fuzzers/FuzzCSSParser.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp index cb8d08ad9f..96caf75624 100644 --- a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp @@ -9,16 +9,21 @@ #include namespace { + struct Globals { Globals(); } globals; -Globals::Globals() { Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); } + +Globals::Globals() +{ + Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); + MUST(Web::Bindings::initialize_main_thread_vm()); +} + } extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - MUST(Web::Bindings::initialize_main_thread_vm()); - // FIXME: There's got to be a better way to do this "correctly" auto& vm = Web::Bindings::main_thread_vm(); (void)Web::parse_css_stylesheet(Web::CSS::Parser::ParsingContext(*vm.current_realm()), { data, size });