mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 19:47:30 -03:00
refactor: Avoid UB in SHA3_256::Write
It is UB to apply a distance to a pointer or iterator further than the end itself, even if the distance is (partially) revoked later on. Fix the issue by advancing the data pointer at most to the end.
This commit is contained in:
parent
fad4032b21
commit
fabeca3458
1 changed files with 2 additions and 2 deletions
|
@ -105,9 +105,9 @@ void KeccakF(uint64_t (&st)[25])
|
|||
|
||||
SHA3_256& SHA3_256::Write(Span<const unsigned char> data)
|
||||
{
|
||||
if (m_bufsize && m_bufsize + data.size() >= sizeof(m_buffer)) {
|
||||
if (m_bufsize && data.size() >= sizeof(m_buffer) - m_bufsize) {
|
||||
// Fill the buffer and process it.
|
||||
std::copy(data.begin(), data.begin() + sizeof(m_buffer) - m_bufsize, m_buffer + m_bufsize);
|
||||
std::copy(data.begin(), data.begin() + (sizeof(m_buffer) - m_bufsize), m_buffer + m_bufsize);
|
||||
data = data.subspan(sizeof(m_buffer) - m_bufsize);
|
||||
m_state[m_pos++] ^= ReadLE64(m_buffer);
|
||||
m_bufsize = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue