Clear UBsan warning -Wstringop-overflow
parent
39418a8512
commit
255a6f2aa0
13
integer.cpp
13
integer.cpp
|
|
@ -3537,9 +3537,9 @@ class KDF2_RNG : public RandomNumberGenerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KDF2_RNG(const byte *seed, size_t seedSize)
|
KDF2_RNG(const byte *seed, size_t seedSize)
|
||||||
: m_counter(0), m_counterAndSeed(seedSize + 4)
|
: m_counter(0), m_counterAndSeed(ClampSize(seedSize) + 4)
|
||||||
{
|
{
|
||||||
memcpy(m_counterAndSeed + 4, seed, seedSize);
|
memcpy(m_counterAndSeed + 4, seed, ClampSize(seedSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateBlock(byte *output, size_t size)
|
void GenerateBlock(byte *output, size_t size)
|
||||||
|
|
@ -3550,6 +3550,15 @@ public:
|
||||||
P1363_KDF2<SHA1>::DeriveKey(output, size, m_counterAndSeed, m_counterAndSeed.size(), NULLPTR, 0);
|
P1363_KDF2<SHA1>::DeriveKey(output, size, m_counterAndSeed, m_counterAndSeed.size(), NULLPTR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UBsan finding, -Wstringop-overflow
|
||||||
|
inline size_t ClampSize(size_t req) const
|
||||||
|
{
|
||||||
|
// Clamp at 16 MB
|
||||||
|
if (req > 16U*1024*1024)
|
||||||
|
return 16U*1024*1024;
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
word32 m_counter;
|
word32 m_counter;
|
||||||
SecByteBlock m_counterAndSeed;
|
SecByteBlock m_counterAndSeed;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue