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

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