Skip to content

Commit

Permalink
Use volatile stores in bytes destructor
Browse files Browse the repository at this point in the history
Ensures that the zeroization can never be optimized out.
  • Loading branch information
rcombs committed Sep 9, 2024
1 parent 7a520f3 commit 77a0e85
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bytes/include/bytes/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ struct bytes
bytes& operator=(bytes&&) = default;

// Zeroize on drop
~bytes() { std::fill(_data.begin(), _data.end(), uint8_t(0)); }
~bytes()
{
auto ptr = static_cast<volatile uint8_t*>(_data.data());
std::fill(ptr, ptr + _data.size(), uint8_t(0));
}

// Mimic std::vector ctors
bytes(size_t count, const uint8_t& value = 0)
Expand Down

0 comments on commit 77a0e85

Please sign in to comment.