Blame SOURCES/tigervnc-passwd-crash-with-malloc-checks.patch

cfbdf6
diff --git a/common/rfb/Password.cxx b/common/rfb/Password.cxx
cfbdf6
index e4a508c..f555c57 100644
cfbdf6
--- a/common/rfb/Password.cxx
cfbdf6
+++ b/common/rfb/Password.cxx
cfbdf6
@@ -55,7 +55,7 @@ PlainPasswd::~PlainPasswd() {
cfbdf6
 
cfbdf6
 void PlainPasswd::replaceBuf(char* b) {
cfbdf6
   if (buf)
cfbdf6
-    memset(buf, 0, strlen(buf));
cfbdf6
+    memset(buf, 0, length ? length : strlen(buf));
cfbdf6
   CharArray::replaceBuf(b);
cfbdf6
 }
cfbdf6
 
55ccb6
diff --git a/common/rfb/util.h b/common/rfb/util.h
cfbdf6
index 3100f90..764692a 100644
55ccb6
--- a/common/rfb/util.h
55ccb6
+++ b/common/rfb/util.h
cfbdf6
@@ -51,16 +51,21 @@ namespace rfb {
55ccb6
     CharArray() : buf(0) {}
55ccb6
     CharArray(char* str) : buf(str) {} // note: assumes ownership
cfbdf6
     CharArray(size_t len) {
cfbdf6
+      length = len;
cfbdf6
       buf = new char[len]();
55ccb6
     }
55ccb6
     ~CharArray() {
cfbdf6
-      delete [] buf;
cfbdf6
+      if (buf) {
cfbdf6
+        delete [] buf;
cfbdf6
+        buf = nullptr;
cfbdf6
+      }
cfbdf6
     }
cfbdf6
     void format(const char *fmt, ...) __printf_attr(2, 3);
cfbdf6
     // Get the buffer pointer & clear it (i.e. caller takes ownership)
cfbdf6
     char* takeBuf() {char* tmp = buf; buf = 0; return tmp;}
cfbdf6
-    void replaceBuf(char* b) {delete [] buf; buf = b;}
cfbdf6
+    void replaceBuf(char* b) {if (buf) delete [] buf; buf = b;}
cfbdf6
     char* buf;
cfbdf6
+    size_t length = 0;
cfbdf6
   private:
cfbdf6
     CharArray(const CharArray&);
cfbdf6
     CharArray& operator=(const CharArray&);