diff options
author | Jeffrey Walton <noloader@gmail.com> | 2021-04-09 03:17:48 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2021-04-09 03:17:48 -0400 |
commit | f1877cb348d46d8c1f0c93969ac816f50815174a (patch) | |
tree | c70ab67d15b4eddf5b6ea746d811ea57e5493060 /secblock.h | |
parent | a608c26dd61a222ff67fa12e3cc25adf39e97a87 (diff) | |
download | cryptopp-git-f1877cb348d46d8c1f0c93969ac816f50815174a.tar.gz |
Shore up SecBlock Append for overlapping buffer
Diffstat (limited to 'secblock.h')
-rw-r--r-- | secblock.h | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -891,9 +891,12 @@ public: /// \since Crypto++ 2.0
void Assign(const T *ptr, size_type len)
{
- New(len);
- if (m_ptr && ptr) // GCC analyzer warning
- memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T));
+ // ptr is unknown. It could be same array or different array.
+ // It could be same array at different offset so m_ptr!=ptr.
+ SecBlock<T, A> t(len);
+ if (t.m_ptr && ptr) // GCC analyzer warning
+ memcpy_s(t.m_ptr, t.m_size*sizeof(T), ptr, len*sizeof(T));
+ std::swap(*this, t);
m_mark = ELEMS_MAX;
}
@@ -948,11 +951,15 @@ public: if (len)
{
- const size_type oldSize = m_size;
- Grow(m_size+len);
- if (m_ptr && ptr) // GCC analyzer warning
- memcpy_s(m_ptr+oldSize, (m_size-oldSize)*sizeof(T), ptr, len*sizeof(T));
-
+ // ptr is unknown. It could be same array or different array.
+ // It could be same array at different offset so m_ptr!=ptr.
+ SecBlock<T, A> t(m_size+len);
+ if (t.m_ptr && m_ptr && ptr) // GCC analyzer warning
+ {
+ memcpy_s(t.m_ptr, t.m_size*sizeof(T), m_ptr, m_size*sizeof(T));
+ memcpy_s(t.m_ptr+m_size, (t.m_size-m_size)*sizeof(T), ptr, len*sizeof(T));
+ }
+ std::swap(*this, t);
}
m_mark = ELEMS_MAX;
}
|