Eliminate potential undefined behavior (RIPD-1685):

Under certain conditions, we could call `memcpy` or `memcmp` with a null
source pointer. Even when specifying 0 as the amount of data to copy this
could result in undefined behavior under the C and C++ standards.

Acknowledgements:
Ripple thanks Guido Vranken for responsibly disclosing these issues.

Bug Bounties and Responsible Disclosures:
We welcome reviews of the rippled code and urge researchers to responsibly
disclose any issues that they may find. For more on Ripple's Bug Bounty
program, please visit: https://ripple.com/bug-bounty
This commit is contained in:
Nik Bougalis
2018-11-07 11:55:24 -08:00
parent 753600a2a0
commit c71eb45240
3 changed files with 13 additions and 39 deletions

View File

@@ -49,14 +49,14 @@ public:
mData.reserve (n);
}
Serializer (void const* data,
std::size_t size)
Serializer (void const* data, std::size_t size)
{
assert(!data == !size);
mData.resize(size);
std::memcpy(mData.data(),
reinterpret_cast<
unsigned char const*>(
data), size);
if (size)
std::memcpy(mData.data(), data, size);
}
Slice slice() const noexcept