From 88938390ba5bb95b9dea840b18745c7a9bf67f72 Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 18 Mar 2013 11:17:34 -0700 Subject: [PATCH] fix track memroy overread on realloc example problem --- cyassl/test.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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);