Skip to content

Commit

Permalink
Merge pull request #2302 from AntelopeIO/cb_environment_ub
Browse files Browse the repository at this point in the history
custom `chainbase::environment` `to_variant()` to workaround invalid unaligned access
  • Loading branch information
spoonincode authored Mar 12, 2024
2 parents 96fb8a4 + 4074b15 commit 07c0c8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
25 changes: 25 additions & 0 deletions libraries/chain/include/eosio/chain/chainbase_environment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <chainbase/environment.hpp>

// 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);

}

}
10 changes: 1 addition & 9 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
#include <eosio/chain_plugin/trx_finality_status_processing.hpp>
#include <eosio/chain/permission_link_object.hpp>
#include <eosio/chain/global_property_object.hpp>
#include <eosio/chain/chainbase_environment.hpp>

#include <eosio/resource_monitor_plugin/resource_monitor_plugin.hpp>

#include <chainbase/environment.hpp>

#include <boost/signals2/connection.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
Expand All @@ -29,13 +28,6 @@
#include <fc/variant.hpp>
#include <cstdlib>

// 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;

Expand Down
11 changes: 1 addition & 10 deletions programs/leap-util/actions/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <eosio/chain/block_log.hpp>
#include <eosio/chain/exceptions.hpp>
#include <chainbase/environment.hpp>
#include <eosio/chain/chainbase_environment.hpp>

#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
Expand All @@ -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();
Expand Down

0 comments on commit 07c0c8c

Please sign in to comment.