Blame SOURCES/tigervnc-covscan.patch

be441b
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
be441b
index 51d77c76..9e277cbb 100644
be441b
--- a/common/network/TcpSocket.cxx
be441b
+++ b/common/network/TcpSocket.cxx
be441b
@@ -736,7 +736,7 @@ char* TcpFilter::patternToStr(const TcpFilter::Pattern& p) {
be441b
                 buffer + 1, sizeof (buffer) - 2, NULL, 0, NI_NUMERICHOST);
be441b
     strcat(buffer, "]");
be441b
     addr.buf = rfb::strDup(buffer);
be441b
-  } else if (p.address.u.sa.sa_family == AF_UNSPEC)
be441b
+  } else
be441b
     addr.buf = rfb::strDup("");
be441b
 
be441b
   char action;
be441b
diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx
be441b
index e1a31f78..d268202b 100644
be441b
--- a/common/rfb/CSecurityTLS.cxx
be441b
+++ b/common/rfb/CSecurityTLS.cxx
be441b
@@ -95,9 +95,9 @@ void CSecurityTLS::setDefaults()
be441b
   delete [] homeDir;
be441b
 
be441b
  if (!fileexists(caDefault.buf))
be441b
-   X509CA.setDefaultStr(strdup(caDefault.buf));
be441b
+   X509CA.setDefaultStr(caDefault.buf);
be441b
  if (!fileexists(crlDefault.buf))
be441b
-   X509CRL.setDefaultStr(strdup(crlDefault.buf));
be441b
+   X509CRL.setDefaultStr(crlDefault.buf);
be441b
 }
be441b
 
be441b
 void CSecurityTLS::shutdown(bool needbye)
be441b
diff --git a/common/rfb/SSecurityPlain.cxx b/common/rfb/SSecurityPlain.cxx
be441b
index 6d48b65c..6f72432a 100644
be441b
--- a/common/rfb/SSecurityPlain.cxx
be441b
+++ b/common/rfb/SSecurityPlain.cxx
be441b
@@ -41,7 +41,7 @@ StringParameter PasswordValidator::plainUsers
be441b
 
be441b
 bool PasswordValidator::validUser(const char* username)
be441b
 {
be441b
-  CharArray users(strDup(plainUsers.getValueStr())), user;
be441b
+  CharArray users(plainUsers.getValueStr()), user;
be441b
 
be441b
   while (users.buf) {
be441b
     strSplit(users.buf, ',', &user.buf, &users.buf);
be441b
diff --git a/unix/tx/TXWindow.cxx b/unix/tx/TXWindow.cxx
be441b
index a6819179..6129840e 100644
be441b
--- a/unix/tx/TXWindow.cxx
be441b
+++ b/unix/tx/TXWindow.cxx
be441b
@@ -24,6 +24,7 @@
be441b
 #include <list>
be441b
 #include <stdio.h>
be441b
 #include <stdlib.h>
be441b
+#include <vector>
be441b
 #include <rfb/util.h>
be441b
 
be441b
 std::list<TXWindow*> windows;
be441b
@@ -132,20 +133,20 @@ TXGlobalEventHandler* TXWindow::setGlobalEventHandler(TXGlobalEventHandler* h)
be441b
 
be441b
 void TXWindow::getColours(Display* dpy, XColor* cols, int nCols)
be441b
 {
be441b
-  bool* got = new bool[nCols];
be441b
+  std::vector<bool> got;
be441b
+
be441b
   bool failed = false;
be441b
   int i;
be441b
   for (i = 0; i < nCols; i++) {
be441b
     if (XAllocColor(dpy, cmap, &cols[i])) {
be441b
-      got[i] = true;
be441b
+      got.push_back(true);
be441b
     } else {
be441b
-      got[i] = false;
be441b
+      got.push_back(false);
be441b
       failed = true;
be441b
     }
be441b
   }
be441b
 
be441b
   if (!failed) {
be441b
-    delete [] got;
be441b
     return;
be441b
   }
be441b
 
be441b
@@ -168,12 +169,13 @@ void TXWindow::getColours(Display* dpy, XColor* cols, int nCols)
be441b
   int cmapSize = DisplayCells(dpy,DefaultScreen(dpy));
be441b
 
be441b
   XColor* cm = new XColor[cmapSize];
be441b
-  bool* shared = new bool[cmapSize];
be441b
-  bool* usedAsNearest = new bool[cmapSize];
be441b
+  std::vector<bool> shared;
be441b
+  std::vector<bool> usedAsNearest;
be441b
 
be441b
   for (i = 0; i < cmapSize; i++) {
be441b
     cm[i].pixel = i;
be441b
-    shared[i] = usedAsNearest[i] = false;
be441b
+    shared.push_back(false);
be441b
+    usedAsNearest.push_back(false);
be441b
   }
be441b
 
be441b
   XQueryColors(dpy, cmap, cm, cmapSize);
be441b
diff --git a/unix/vncpasswd/vncpasswd.cxx b/unix/vncpasswd/vncpasswd.cxx
be441b
index 8bd4e48e..3055223e 100644
be441b
--- a/unix/vncpasswd/vncpasswd.cxx
be441b
+++ b/unix/vncpasswd/vncpasswd.cxx
be441b
@@ -134,7 +134,7 @@ int main(int argc, char** argv)
be441b
     } else if (argv[i][0] == '-') {
be441b
       usage();
be441b
     } else if (!fname) {
be441b
-      fname = argv[i];
be441b
+      fname = strDup(argv[i]);
be441b
     } else {
be441b
       usage();
be441b
     }
be441b
@@ -165,24 +165,37 @@ int main(int argc, char** argv)
be441b
     FILE* fp = fopen(fname,"w");
be441b
     if (!fp) {
be441b
       fprintf(stderr,"Couldn't open %s for writing\n",fname);
be441b
+      delete [] fname;
be441b
+      delete obfuscated;
be441b
+      delete obfuscatedReadOnly;
be441b
       exit(1);
be441b
     }
be441b
     chmod(fname, S_IRUSR|S_IWUSR);
be441b
 
be441b
     if (fwrite(obfuscated->buf, obfuscated->length, 1, fp) != 1) {
be441b
       fprintf(stderr,"Writing to %s failed\n",fname);
be441b
+      delete [] fname;
be441b
+      delete obfuscated;
be441b
+      delete obfuscatedReadOnly;
be441b
       exit(1);
be441b
     }
be441b
 
be441b
+    delete obfuscated;
be441b
+
be441b
     if (obfuscatedReadOnly) {
be441b
       if (fwrite(obfuscatedReadOnly->buf, obfuscatedReadOnly->length, 1, fp) != 1) {
be441b
         fprintf(stderr,"Writing to %s failed\n",fname);
be441b
+        delete [] fname;
be441b
+        delete obfuscatedReadOnly;
be441b
         exit(1);
be441b
       }
be441b
     }
be441b
 
be441b
     fclose(fp);
be441b
 
be441b
+    delete [] fname;
be441b
+    delete obfuscatedReadOnly;
be441b
+
be441b
     return 0;
be441b
   }
be441b
 }
be441b
diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc
be441b
index d6f6b742..7ca71d94 100644
be441b
--- a/unix/xserver/hw/vnc/vncExtInit.cc
be441b
+++ b/unix/xserver/hw/vnc/vncExtInit.cc
be441b
@@ -184,7 +184,7 @@ void vncExtensionInit(void)
be441b
             listeners.push_back(new network::TcpListener(vncInetdSock));
be441b
             vlog.info("inetd wait");
be441b
           }
be441b
-        } else if (rfbunixpath.getValueStr()[0] != '\0') {
be441b
+        } else if (((const char*)rfbunixpath)[0] != '\0') {
be441b
           char path[PATH_MAX];
be441b
           int mode = (int)rfbunixmode;
be441b
 
be441b
@@ -192,7 +192,7 @@ void vncExtensionInit(void)
be441b
             strncpy(path, rfbunixpath, sizeof(path));
be441b
           else
be441b
             snprintf(path, sizeof(path), "%s.%d",
be441b
-                     rfbunixpath.getValueStr(), scr);
be441b
+                     (const char*)rfbunixpath, scr);
be441b
           path[sizeof(path)-1] = '\0';
be441b
 
be441b
           listeners.push_back(new network::UnixListener(path, mode));
be441b
diff --git a/unix/xserver/hw/vnc/vncSelection.c b/unix/xserver/hw/vnc/vncSelection.c
be441b
index 51dfd9c6..4f3538d4 100644
be441b
--- a/unix/xserver/hw/vnc/vncSelection.c
be441b
+++ b/unix/xserver/hw/vnc/vncSelection.c
be441b
@@ -105,7 +105,7 @@ void vncClientCutText(const char* str, int len)
be441b
       LOG_ERROR("Could not set PRIMARY selection");
be441b
   }
be441b
 
be441b
-  vncOwnSelection(xaCLIPBOARD);
be441b
+  rc = vncOwnSelection(xaCLIPBOARD);
be441b
   if (rc != Success)
be441b
     LOG_ERROR("Could not set CLIPBOARD selection");
be441b
 }
be441b
diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c
be441b
index 3b4d2f31..c845ebc4 100644
be441b
--- a/unix/xserver/hw/vnc/xvnc.c
be441b
+++ b/unix/xserver/hw/vnc/xvnc.c
be441b
@@ -766,10 +766,13 @@ vfbUninstallColormap(ColormapPtr pmap)
be441b
 	    curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
be441b
 						   RT_COLORMAP);
be441b
 #else
be441b
-	    dixLookupResourceByType((void * *) &curpmap, pmap->pScreen->defColormap,
be441b
-				    RT_COLORMAP, serverClient, DixUnknownAccess);
be441b
+	    int rc =  dixLookupResourceByType((void * *) &curpmap, pmap->pScreen->defColormap,
be441b
+					      RT_COLORMAP, serverClient, DixUnknownAccess);
be441b
+	    if (rc != Success)
be441b
+		ErrorF("Failed to uninstall color map\n");
be441b
+	    else
be441b
 #endif
be441b
-	    (*pmap->pScreen->InstallColormap)(curpmap);
be441b
+		(*pmap->pScreen->InstallColormap)(curpmap);
be441b
 	}
be441b
     }
be441b
 }
be441b
diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx
be441b
index d070b648..1843485a 100644
be441b
--- a/vncviewer/DesktopWindow.cxx
be441b
+++ b/vncviewer/DesktopWindow.cxx
be441b
@@ -103,12 +103,12 @@ DesktopWindow::DesktopWindow(int w, int h, const char *name,
be441b
   int geom_x = 0, geom_y = 0;
be441b
   if (strcmp(geometry, "") != 0) {
be441b
     int matched;
be441b
-    matched = sscanf(geometry.getValueStr(), "+%d+%d", &geom_x, &geom_y);
be441b
+    matched = sscanf((const char*)geometry, "+%d+%d", &geom_x, &geom_y);
be441b
     if (matched == 2) {
be441b
       force_position(1);
be441b
     } else {
be441b
       int geom_w, geom_h;
be441b
-      matched = sscanf(geometry.getValueStr(), "%dx%d+%d+%d", &geom_w, &geom_h, &geom_x, &geom_y);
be441b
+      matched = sscanf((const char*)geometry, "%dx%d+%d+%d", &geom_w, &geom_h, &geom_x, &geom_y);
be441b
       switch (matched) {
be441b
       case 4:
be441b
         force_position(1);
be441b
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
be441b
index b018c95b..62b5d9c5 100644
be441b
--- a/vncviewer/OptionsDialog.cxx
be441b
+++ b/vncviewer/OptionsDialog.cxx
be441b
@@ -282,7 +282,7 @@ void OptionsDialog::loadOptions(void)
be441b
   /* Screen */
be441b
   int width, height;
be441b
 
be441b
-  if (sscanf(desktopSize.getValueStr(), "%dx%d", &width, &height) != 2) {
be441b
+  if (sscanf((const char*)desktopSize, "%dx%d", &width, &height) != 2) {
be441b
     desktopSizeCheckbox->value(false);
be441b
     desktopWidthInput->value("1024");
be441b
     desktopHeightInput->value("768");
be441b
diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx
be441b
index de67f87b..fec17896 100644
be441b
--- a/vncviewer/ServerDialog.cxx
be441b
+++ b/vncviewer/ServerDialog.cxx
be441b
@@ -150,7 +150,7 @@ void ServerDialog::handleLoad(Fl_Widget *widget, void *data)
be441b
     return;
be441b
   }
be441b
   
be441b
-  const char* filename = strdup(file_chooser->value());
be441b
+  const char* filename = file_chooser->value();
be441b
 
be441b
   try {
be441b
     dialog->serverName->value(loadViewerParameters(filename));
be441b
@@ -165,8 +165,8 @@ void ServerDialog::handleLoad(Fl_Widget *widget, void *data)
be441b
 void ServerDialog::handleSaveAs(Fl_Widget *widget, void *data)
be441b
 { 
be441b
   ServerDialog *dialog = (ServerDialog*)data;
be441b
-  const char* servername = strdup(dialog->serverName->value());
be441b
-  char* filename;
be441b
+  const char* servername = dialog->serverName->value();
be441b
+  const char* filename;
be441b
 
be441b
   Fl_File_Chooser* file_chooser = new Fl_File_Chooser("", _("TigerVNC configuration (*.tigervnc)"), 
be441b
 						      2, _("Save the TigerVNC configuration to file"));
be441b
@@ -187,7 +187,7 @@ void ServerDialog::handleSaveAs(Fl_Widget *widget, void *data)
be441b
       return;
be441b
     }
be441b
     
be441b
-    filename = strdup(file_chooser->value());
be441b
+    filename = file_chooser->value();
be441b
     
be441b
     FILE* f = fopen(filename, "r");
be441b
     if (f) {
be441b
@@ -235,7 +235,7 @@ void ServerDialog::handleCancel(Fl_Widget *widget, void *data)
be441b
 void ServerDialog::handleConnect(Fl_Widget *widget, void *data)
be441b
 {
be441b
   ServerDialog *dialog = (ServerDialog*)data;
be441b
-  const char* servername = strdup(dialog->serverName->value());
be441b
+  const char* servername = dialog->serverName->value();
be441b
 
be441b
   dialog->hide();
be441b
   
be441b
diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx
be441b
index 51cce3d7..94cc1b05 100644
be441b
--- a/vncviewer/parameters.cxx
be441b
+++ b/vncviewer/parameters.cxx
be441b
@@ -499,6 +499,7 @@ void saveViewerParameters(const char *filename, const char *servername) {
be441b
     }
be441b
 
be441b
     snprintf(filepath, sizeof(filepath), "%sdefault.tigervnc", homeDir);
be441b
+    free(homeDir);
be441b
   } else {
be441b
     snprintf(filepath, sizeof(filepath), "%s", filename);
be441b
   }
be441b
@@ -555,6 +556,7 @@ char* loadViewerParameters(const char *filename) {
be441b
                         "can't obtain home directory path."));
be441b
 
be441b
     snprintf(filepath, sizeof(filepath), "%sdefault.tigervnc", homeDir);
be441b
+    free(homeDir);
be441b
   } else {
be441b
     snprintf(filepath, sizeof(filepath), "%s", filename);
be441b
   }
be441b
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
be441b
index f076565f..a9d4dfea 100644
be441b
--- a/vncviewer/vncviewer.cxx
be441b
+++ b/vncviewer/vncviewer.cxx
be441b
@@ -470,9 +470,9 @@ static int mktunnel()
be441b
   int localPort = findFreeTcpPort();
be441b
   int remotePort;
be441b
 
be441b
-  gatewayHost = strDup(via.getValueStr());
be441b
   if (interpretViaParam(remoteHost, &remotePort, localPort) != 0)
be441b
     return 1;
be441b
+  gatewayHost = (const char*)via;
be441b
   createTunnel(gatewayHost, remoteHost, remotePort, localPort);
be441b
 
be441b
   return 0;