Skip to content

Commit fabeca3

Browse files
author
MarcoFalke
committed
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.
1 parent fad4032 commit fabeca3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/crypto/sha3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ void KeccakF(uint64_t (&st)[25])
105105

106106
SHA3_256& SHA3_256::Write(Span<const unsigned char> data)
107107
{
108-
if (m_bufsize && m_bufsize + data.size() >= sizeof(m_buffer)) {
108+
if (m_bufsize && data.size() >= sizeof(m_buffer) - m_bufsize) {
109109
// Fill the buffer and process it.
110-
std::copy(data.begin(), data.begin() + sizeof(m_buffer) - m_bufsize, m_buffer + m_bufsize);
110+
std::copy(data.begin(), data.begin() + (sizeof(m_buffer) - m_bufsize), m_buffer + m_bufsize);
111111
data = data.subspan(sizeof(m_buffer) - m_bufsize);
112112
m_state[m_pos++] ^= ReadLE64(m_buffer);
113113
m_bufsize = 0;

0 commit comments

Comments
 (0)