From 4074b15a7672c71df2f40932d7e8f37573e25afd Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:23:03 -0400 Subject: [PATCH] specialized to_variant() for chainbase::environment's packedness --- .../eosio/chain/chainbase_environment.hpp | 25 +++++++++++++++++++ plugins/chain_plugin/chain_plugin.cpp | 10 +------- programs/leap-util/actions/chain.cpp | 11 +------- 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 libraries/chain/include/eosio/chain/chainbase_environment.hpp diff --git a/libraries/chain/include/eosio/chain/chainbase_environment.hpp b/libraries/chain/include/eosio/chain/chainbase_environment.hpp new file mode 100644 index 0000000000..9f858655fb --- /dev/null +++ b/libraries/chain/include/eosio/chain/chainbase_environment.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +// reflect chainbase::environment for --print-build-info option +FC_REFLECT_ENUM(chainbase::environment::os_t, + (OS_LINUX) (OS_MACOS) (OS_WINDOWS) (OS_OTHER)) +FC_REFLECT_ENUM(chainbase::environment::arch_t, + (ARCH_X86_64) (ARCH_ARM) (ARCH_RISCV) (ARCH_OTHER)) + +namespace fc { + +void to_variant(const chainbase::environment& bi, variant& v) { + // the variant conversion ultimately binds a reference to each member, but chainbase::environment is packed making + // a reference to an unaligned variable UB. The boost_version is the only offender + unsigned aligned_boost_version = bi.boost_version; + v = fc::mutable_variant_object()("debug", bi.debug) + ("os", bi.os) + ("arch", bi.arch) + ("boost_version", aligned_boost_version) + ("compiler", bi.compiler); + +} + +} \ No newline at end of file diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index c3362c411d..f353b66803 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -16,11 +16,10 @@ #include #include #include +#include #include -#include - #include #include #include @@ -29,13 +28,6 @@ #include #include -// reflect chainbase::environment for --print-build-info option -FC_REFLECT_ENUM( chainbase::environment::os_t, - (OS_LINUX)(OS_MACOS)(OS_WINDOWS)(OS_OTHER) ) -FC_REFLECT_ENUM( chainbase::environment::arch_t, - (ARCH_X86_64)(ARCH_ARM)(ARCH_RISCV)(ARCH_OTHER) ) -FC_REFLECT(chainbase::environment, (debug)(os)(arch)(boost_version)(compiler) ) - const std::string deep_mind_logger_name("deep-mind"); eosio::chain::deep_mind_handler _deep_mind_log; diff --git a/programs/leap-util/actions/chain.cpp b/programs/leap-util/actions/chain.cpp index 9a12a3b21c..25e71e38ec 100644 --- a/programs/leap-util/actions/chain.cpp +++ b/programs/leap-util/actions/chain.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -19,15 +19,6 @@ using namespace eosio; using namespace eosio::chain; - -// reflect chainbase::environment for --print-build-info option -FC_REFLECT_ENUM(chainbase::environment::os_t, - (OS_LINUX) (OS_MACOS) (OS_WINDOWS) (OS_OTHER)) -FC_REFLECT_ENUM(chainbase::environment::arch_t, - (ARCH_X86_64) (ARCH_ARM) (ARCH_RISCV) (ARCH_OTHER)) -FC_REFLECT(chainbase::environment, (debug) (os) (arch) (boost_version) (compiler)) - - void chain_actions::setup(CLI::App& app) { auto* sub = app.add_subcommand("chain-state", "chain utility"); sub->add_option("--state-dir", opt->sstate_state_dir, "The location of the state directory (absolute path or relative to the current directory)")->capture_default_str();