From 5181ac037cd05aa439eb0da6f94b58db486db5b1 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 8 Mar 2014 19:15:24 -0700 Subject: [PATCH] Protect MemBlob::append() against raw-space writes There is no guarantee that the 'unused' area of MemBlob is actually unused. For example if a read buffer was being filled into the rawSpace() of a SBuf or MemBlob it will overlap with this empty area until a read call updates the related size state in MemBlob/SBuf. For these cases we must use memmove() which guarantees no buffer corruption will take place on memory overlaps. --- src/MemBlob.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MemBlob.cc b/src/MemBlob.cc index e01671e208..1439de1097 100644 --- a/src/MemBlob.cc +++ b/src/MemBlob.cc @@ -122,8 +122,7 @@ MemBlob::append(const char *source, const size_type n) if (n > 0) { // appending zero bytes is allowed but only affects the stats Must(willFit(n)); Must(source); - /// \note memcpy() is safe because we copy to an unused area - memcpy(mem + size, source, n); + memmove(mem + size, source, n); size += n; } ++Stats.append; -- 2.47.2