diff --git a/cyassl/test.h b/cyassl/test.h index bc41a7d46..bc93e7ace 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -1011,6 +1011,14 @@ static INLINE int CurrentDir(const char* str) { void* ret = TrackMalloc(sz); + if (ptr) { + /* if realloc is bigger, don't overread old ptr */ + memoryTrack* mt = (memoryTrack*)((byte*)ptr - sizeof(memoryTrack)); + + if (mt->u.hint.thisSize < sz) + sz = mt->u.hint.thisSize; + } + if (ret && ptr) memcpy(ret, ptr, sz);