]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Protect MemBlob::append() against raw-space writes
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 9 Mar 2014 01:47:23 +0000 (18:47 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 9 Mar 2014 01:47:23 +0000 (18:47 -0700)
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

index 8cb0c8044efef6fa27acc3d2a4946789f5f71c15..1c26f6a5d43f82538f359f0dbf43487ae768d7dd 100644 (file)
@@ -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;