diff options
author | Jeffrey Walton <noloader@gmail.com> | 2019-04-27 21:08:02 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2019-04-27 21:08:02 -0400 |
commit | 255a6f2aa06e788a33ce8f978460ed22af22e4d3 (patch) | |
tree | 2b5f7073d913f9869e30dc6ee580bdb1ebc2e370 /integer.cpp | |
parent | 39418a85122fa7954cca6354be30a44d6335874e (diff) | |
download | cryptopp-git-255a6f2aa06e788a33ce8f978460ed22af22e4d3.tar.gz |
Clear UBsan warning -Wstringop-overflow
Diffstat (limited to 'integer.cpp')
-rw-r--r-- | integer.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/integer.cpp b/integer.cpp index 78dd10a1..9af43bfa 100644 --- a/integer.cpp +++ b/integer.cpp @@ -3537,9 +3537,9 @@ class KDF2_RNG : public RandomNumberGenerator {
public:
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)
@@ -3550,6 +3550,15 @@ public: 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:
word32 m_counter;
SecByteBlock m_counterAndSeed;
|