Skip to content

Commit fabbde3

Browse files
committed
Merge pull request #9450
ed955bf build: fix build with Boost 1.85 and remove instances of viewkey logging (jeffro256)
2 parents a1dc85c + ed955bf commit fabbde3

File tree

20 files changed

+65
-60
lines changed

20 files changed

+65
-60
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ endif()
10911091
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS})
10921092
add_definitions(-DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION)
10931093
add_definitions(-DBOOST_NO_AUTO_PTR)
1094+
add_definitions(-DBOOST_UUID_DISABLE_ALIGNMENT) # This restores UUID's std::has_unique_object_representations property
10941095

10951096
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})
10961097
if(NOT Boost_FOUND)

contrib/epee/include/serialization/keyvalue_serialization.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,18 @@ public: \
9898
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
9999
epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.varialble, stg, hparent_section, val_name);
100100

101-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, val_name) \
102-
static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
103-
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name)
101+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, val_name) \
102+
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
103+
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
104+
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name)
104105

105-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, val_name, default_value) \
106+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, val_name, default_value) \
106107
do { \
107-
static_assert(std::is_pod<decltype(this_ref.varialble)>::value, "t_type must be a POD type."); \
108-
bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
108+
static_assert(std::is_trivially_copyable_v<decltype(this_ref.variable)>, "t_type must be a trivially copyable type."); \
109+
static_assert(std::is_standard_layout_v<decltype(this_ref.variable)>, "t_type must be a standard layout type."); \
110+
bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name) \
109111
if (!ret) \
110-
epee::serialize_default(this_ref.varialble, default_value); \
112+
epee::serialize_default(this_ref.variable, default_value); \
111113
} while(0);
112114

113115
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, val_name) \
@@ -118,7 +120,7 @@ public: \
118120
#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
119121
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
120122
#define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(varialble, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(varialble, #varialble, def)
121-
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_pod compile time check
123+
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_trivially_copyable and is_standard_layout compile time check
122124
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
123125
#define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value)
124126

contrib/epee/include/span.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,13 @@ namespace epee
133133
return {src.data(), src.size()};
134134
}
135135

136-
template<typename T>
137-
constexpr bool has_padding() noexcept
138-
{
139-
return !std::is_standard_layout<T>() || alignof(T) != 1;
140-
}
141-
142136
//! \return Cast data from `src` as `span<const std::uint8_t>`.
143137
template<typename T>
144138
span<const std::uint8_t> to_byte_span(const span<const T> src) noexcept
145139
{
146-
static_assert(!has_padding<T>(), "source type may have padding");
140+
static_assert(!std::is_empty<T>(), "empty value types will not work -> sizeof == 1");
141+
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
142+
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
147143
return {reinterpret_cast<const std::uint8_t*>(src.data()), src.size_bytes()};
148144
}
149145

@@ -153,7 +149,8 @@ namespace epee
153149
{
154150
using value_type = typename T::value_type;
155151
static_assert(!std::is_empty<value_type>(), "empty value types will not work -> sizeof == 1");
156-
static_assert(!has_padding<value_type>(), "source value type may have padding");
152+
static_assert(std::is_standard_layout_v<value_type>, "value type must have standard layout");
153+
static_assert(std::has_unique_object_representations_v<value_type>, "value type must be trivially copyable with no padding");
157154
return {reinterpret_cast<std::uint8_t*>(src.data()), src.size() * sizeof(value_type)};
158155
}
159156

@@ -162,7 +159,8 @@ namespace epee
162159
span<const std::uint8_t> as_byte_span(const T& src) noexcept
163160
{
164161
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
165-
static_assert(!has_padding<T>(), "source type may have padding");
162+
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
163+
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
166164
return {reinterpret_cast<const std::uint8_t*>(std::addressof(src)), sizeof(T)};
167165
}
168166

@@ -171,7 +169,8 @@ namespace epee
171169
span<std::uint8_t> as_mut_byte_span(T& src) noexcept
172170
{
173171
static_assert(!std::is_empty<T>(), "empty types will not work -> sizeof == 1");
174-
static_assert(!has_padding<T>(), "source type may have padding");
172+
static_assert(std::is_standard_layout_v<T>, "type must have standard layout");
173+
static_assert(std::has_unique_object_representations_v<T>, "type must be trivially copyable with no padding");
175174
return {reinterpret_cast<std::uint8_t*>(std::addressof(src)), sizeof(T)};
176175
}
177176

contrib/epee/include/string_tools.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ namespace string_tools
8989
std::string pod_to_hex(const t_pod_type& s)
9090
{
9191
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
92+
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
9293
return to_hex::string(as_byte_span(s));
9394
}
9495
//----------------------------------------------------------------------------
9596
template<class t_pod_type>
9697
bool hex_to_pod(const boost::string_ref hex_str, t_pod_type& s)
9798
{
9899
static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type");
100+
static_assert(std::has_unique_object_representations_v<t_pod_type>, "type may have padding");
99101
return from_hex::to_buffer(as_mut_byte_span(s), hex_str);
100102
}
101103
//----------------------------------------------------------------------------

src/crypto/crypto.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ namespace crypto {
171171
/* Generate a value filled with random bytes.
172172
*/
173173
template<typename T>
174-
typename std::enable_if<std::is_pod<T>::value, T>::type rand() {
174+
T rand() {
175+
static_assert(std::is_standard_layout_v<T>, "cannot write random bytes into non-standard layout type");
176+
static_assert(std::is_trivially_copyable_v<T>, "cannot write random bytes into non-trivially copyable type");
175177
typename std::remove_cv<T>::type res;
176178
generate_random_bytes_thread_safe(sizeof(T), (uint8_t*)&res);
177179
return res;
@@ -314,8 +316,14 @@ namespace crypto {
314316
inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) {
315317
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
316318
}
317-
inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) {
318-
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
319+
/* Do NOT overload the << operator for crypto::secret_key here. Use secret_key_explicit_print_ref
320+
* instead to prevent accidental implicit dumping of secret key material to the logs (which has
321+
* happened before). For the same reason, do not overload it for crypto::ec_scalar either since
322+
* crypto::secret_key is a subclass. I'm not sorry that it's obtuse; that's the point, bozo.
323+
*/
324+
struct secret_key_explicit_print_ref { const crypto::secret_key &sk; };
325+
inline std::ostream &operator <<(std::ostream &o, const secret_key_explicit_print_ref v) {
326+
epee::to_hex::formatted(o, epee::as_byte_span(unwrap(unwrap(v.sk)))); return o;
319327
}
320328
inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) {
321329
epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace cryptonote
292292
bool r = hwdev.generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation);
293293
if (!r)
294294
{
295-
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")");
295+
MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", <viewkey>)");
296296
memcpy(&recv_derivation, rct::identity().bytes, sizeof(recv_derivation));
297297
}
298298

@@ -303,7 +303,7 @@ namespace cryptonote
303303
r = hwdev.generate_key_derivation(additional_tx_public_keys[i], ack.m_view_secret_key, additional_recv_derivation);
304304
if (!r)
305305
{
306-
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", " << ack.m_view_secret_key << ")");
306+
MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", <viewkey>)");
307307
}
308308
else
309309
{

src/cryptonote_core/cryptonote_tx_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace cryptonote
144144
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
145145
crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key);
146146
bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
147-
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")");
147+
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{txkey.sec} << ")");
148148

149149
r = crypto::derive_public_key(derivation, no, miner_address.m_spend_public_key, out_eph_public_key);
150150
CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << no << ", "<< miner_address.m_spend_public_key << ")");
@@ -484,7 +484,7 @@ namespace cryptonote
484484
crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data());
485485
ss_ring_s << "signatures:" << ENDL;
486486
std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;});
487-
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL;
487+
ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << crypto::secret_key_explicit_print_ref{in_contexts[i].in_ephemeral.sec} << ENDL << "real_output: " << src_entr.real_output << ENDL;
488488
i++;
489489
}
490490

src/cryptonote_protocol/block_queue.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@
4040
#undef MONERO_DEFAULT_LOG_CATEGORY
4141
#define MONERO_DEFAULT_LOG_CATEGORY "cn.block_queue"
4242

43-
namespace std {
44-
static_assert(sizeof(size_t) <= sizeof(boost::uuids::uuid), "boost::uuids::uuid too small");
45-
template<> struct hash<boost::uuids::uuid> {
46-
std::size_t operator()(const boost::uuids::uuid &_v) const {
47-
return reinterpret_cast<const std::size_t &>(_v);
48-
}
49-
};
50-
}
51-
5243
namespace cryptonote
5344
{
5445

@@ -472,15 +463,15 @@ bool block_queue::has_spans(const boost::uuids::uuid &connection_id) const
472463
float block_queue::get_speed(const boost::uuids::uuid &connection_id) const
473464
{
474465
boost::unique_lock<boost::recursive_mutex> lock(mutex);
475-
std::unordered_map<boost::uuids::uuid, float> speeds;
466+
std::unordered_map<boost::uuids::uuid, float, boost::hash<boost::uuids::uuid>> speeds;
476467
for (const auto &span: blocks)
477468
{
478469
if (span.blocks.empty())
479470
continue;
480471
// note that the average below does not average over the whole set, but over the
481472
// previous pseudo average and the latest rate: this gives much more importance
482473
// to the latest measurements, which is fine here
483-
std::unordered_map<boost::uuids::uuid, float>::iterator i = speeds.find(span.connection_id);
474+
const auto i = speeds.find(span.connection_id);
484475
if (i == speeds.end())
485476
speeds.insert(std::make_pair(span.connection_id, span.rate));
486477
else

src/device/device_default.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,15 @@ namespace hw {
317317
{
318318
// sending change to yourself; derivation = a*R
319319
r = generate_key_derivation(txkey_pub, sender_account_keys.m_view_secret_key, derivation);
320-
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", " << sender_account_keys.m_view_secret_key << ")");
320+
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", <viewkey>)");
321321
}
322322
else
323323
{
324324
// sending to the recipient; derivation = r*A (or s*C in the subaddress scheme)
325-
r = generate_key_derivation(dst_entr.addr.m_view_public_key, dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key, derivation);
326-
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << (dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")");
325+
const crypto::secret_key &tx_privkey{dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key};
326+
r = generate_key_derivation(dst_entr.addr.m_view_public_key, tx_privkey, derivation);
327+
CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation("
328+
<< dst_entr.addr.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{tx_privkey} << ")");
327329
}
328330

329331
if (need_additional_txkeys)

src/lmdb/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ namespace lmdb
127127
/*!
128128
A LMDB comparison function that uses `std::memcmp`.
129129
130-
\toaram T is `!epee::has_padding`
130+
\toaram T has standard layout and an alignment of 1
131131
\tparam offset to `T` within the value.
132132
133133
\return The result of `std::memcmp` over the value.
134134
*/
135135
template<typename T, std::size_t offset = 0>
136136
inline int compare(MDB_val const* left, MDB_val const* right) noexcept
137137
{
138-
static_assert(!epee::has_padding<T>(), "memcmp will not work");
138+
static_assert(std::is_standard_layout_v<T> && alignof(T) == 1, "memcmp will not work");
139139
if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset)
140140
{
141141
assert("invalid use of custom comparison" == 0);

0 commit comments

Comments
 (0)