]> source.dussan.org Git - tigervnc.git/commitdiff
Prevent double free by crafted fences. 438/head
authorMichal Srb <michalsrb@gmail.com>
Mon, 27 Mar 2017 16:02:15 +0000 (19:02 +0300)
committerMichal Srb <michalsrb@gmail.com>
Mon, 27 Mar 2017 16:02:15 +0000 (19:02 +0300)
If client sent fence with some data, followed by fence with no data (length 0), the original fence data were freed, but the pointer kept pointing at them. Sending one more fence would attempt to free them again.

common/rfb/SMsgWriter.cxx
common/rfb/VNCSConnectionST.cxx

index cf3264e8f0ddcbdecb5d9063a83935c69face29a..bc3f43987c09ad9e68fc221e863c7792e4a07c64 100644 (file)
@@ -101,7 +101,9 @@ void SMsgWriter::writeFence(rdr::U32 flags, unsigned len, const char data[])
   os->writeU32(flags);
 
   os->writeU8(len);
-  os->writeBytes(data, len);
+
+  if (len > 0)
+    os->writeBytes(data, len);
 
   endMsg();
 }
index 0a2ca334ec4ee5bd331ab99b6f2bf4ab7af20e2f..d2206f9ba6014a37de2c07a06e67ba3e158d22f5 100644 (file)
@@ -666,6 +666,7 @@ void VNCSConnectionST::fence(rdr::U32 flags, unsigned len, const char data[])
       fenceFlags = flags & (fenceFlagBlockBefore | fenceFlagBlockAfter | fenceFlagSyncNext);
       fenceDataLen = len;
       delete [] fenceData;
+      fenceData = NULL;
       if (len > 0) {
         fenceData = new char[len];
         memcpy(fenceData, data, len);