-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2302 from AntelopeIO/cb_environment_ub
custom `chainbase::environment` `to_variant()` to workaround invalid unaligned access
- Loading branch information
Showing
3 changed files
with
27 additions
and
19 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
libraries/chain/include/eosio/chain/chainbase_environment.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters