lidtsvc: coverity fixes
authorPeter Howkins <flibble@users.sf.net>
Thu, 12 Apr 2018 00:38:02 +0000 (01:38 +0100)
committerPeter Howkins <flibble@users.sf.net>
Thu, 12 Apr 2018 00:38:02 +0000 (01:38 +0100)
17 files changed:
cde/lib/DtSvc/DtCodelibs/filegen.C
cde/lib/DtSvc/DtEncap/connect.c
cde/lib/DtSvc/DtEncap/noio.c
cde/lib/DtSvc/DtEncap/pipe.c
cde/lib/DtSvc/DtEncap/spc-exec.c
cde/lib/DtSvc/DtEncap/spc-net.c
cde/lib/DtSvc/DtEncap/spc-proto.c
cde/lib/DtSvc/DtUtil1/Action.c
cde/lib/DtSvc/DtUtil1/ActionDb.c
cde/lib/DtSvc/DtUtil1/ActionFind.c
cde/lib/DtSvc/DtUtil1/DndFile.c
cde/lib/DtSvc/DtUtil1/Dts.c
cde/lib/DtSvc/DtUtil1/DtsDb.c
cde/lib/DtSvc/DtUtil1/MMDb.c
cde/lib/DtSvc/DtUtil2/EnvControl.c
cde/lib/DtSvc/DtUtil2/PrintXErr.c
cde/lib/DtSvc/DtUtil2/SmCreateDirs.c

index ad8c8de4b32b5aeca93f83b92c6f9c08c58d7764..c4a038844e8f5d681f70ea4eb141c4e138536592 100644 (file)
@@ -28,6 +28,7 @@
  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  * (c) Copyright 1993, 1994 Novell, Inc.
  */
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -274,7 +275,7 @@ _SHXbuf::filegen()
     {
        long i;
        // compare all entries to a copy of the first entry
-       strcpy(filebuf, &bufptr[long(vec[0])]);
+       snprintf(filebuf, sizeof(filebuf), "%s", &bufptr[long(vec[0])]);
 
        for (i = 1; i < vec.size(); i++)
        {
index 83f1087f65c7823cdc2eb4732f071b5d5c7d63a8..47dd204455d8ed2cc625bd9ad6d420212354fbf5 100644 (file)
@@ -74,6 +74,7 @@ XeCreateContextString(XeString host,
 
    if ((strequal(directory, (XeString)"")) || (directory == NULL)){
       if ((strequal(file, (XeString)"")) || (file == NULL)){
+         Xe_release_str(host);
         return((XeString) NULL);
       } else {
         context_string = XeMalloc (strlen(host) + strlen(file) + 2);
index 409cd4f112121adeff1fd214b92532391cfd16ed..86ee22e31e8a13f7690fc58237d15ede5c6540d7 100644 (file)
@@ -197,6 +197,7 @@ static char * get_tmp_dir (
    if (is_dir_usable (dir))
       return (dir);
 
+   free(dir);
    return (NULL);
 }
 
index 6cf76c91999baf9e72be9a05c2b45e97c24a8222..c3b5f04c4c3ce0d497fa9a7758cf354f55c0f5c7 100644 (file)
@@ -89,6 +89,7 @@ Wire *getpipe(Wire *prevwire)
   /* Get file descriptors for pipe */
   if (pipe(wire_ptr->fd) < OK) {
     SPC_Error(SPC_No_Pipe);
+    XeFree(wire_ptr);
     return(SPC_ERROR);
   }
   return(wire_ptr);
index 38889d4cc464a0cbda6b2da6421e910769b1b809..ac01ccc14dd08e959771b2c96350581118ced4f9 100644 (file)
@@ -441,9 +441,11 @@ int exec_proc_local_channel_object(SPC_Channel_Ptr channel)
        }
     }
 
-    if(mempf0(channel, pre_fork)==SPC_ERROR)
-       return(SPC_ERROR);
-    
+    if(mempf0(channel, pre_fork)==SPC_ERROR) {
+        XeFree(dir);
+        return(SPC_ERROR);
+    }
+
     /* When using HP NLIO (xj0input) we have a problem.  Namely,  */
     /* the xj0 processs uses signal() to deal with SIGCLD which   */   
     /* is incompatible with sigaction/sigprogmask/etc.  Even      */
@@ -458,9 +460,11 @@ int exec_proc_local_channel_object(SPC_Channel_Ptr channel)
     sigemptyset(&oldsigmask);
     sigaddset(&newsigmask, SIGCHLD);
     
-    if (sigprocmask(SIG_BLOCK, &newsigmask, &oldsigmask) == ERROR)
-       return(SPC_ERROR);
-    
+    if (sigprocmask(SIG_BLOCK, &newsigmask, &oldsigmask) == ERROR) {
+        XeFree(dir);
+        return(SPC_ERROR);
+    }
+
     pid = channel->pid = fork();
     
     /*
index 71a5d6da0e16203e4803dad337e777e82d2937cc..aa0f58084acb42f81096961add147c7db002c052 100644 (file)
@@ -344,8 +344,10 @@ SPC_Contact_Server(SPC_Connection_Ptr connection)
   memcpy(&saddr.sin_addr, remote->h_addr, remote->h_length);
 
   if(connect(connection->sid, (struct sockaddr *)&saddr, sizeof(saddr)) == ERROR) {
-    SPC_Error(SPC_Bad_Connect,
-             XeFindShortHost(remote->h_name));
+    XeString shorthost = XeFindShortHost(remote->h_name);
+    SPC_Error(SPC_Bad_Connect, shorthost);
+    XeFree(shorthost);
+    
     return(SPC_ERROR);
   }
 
index 92fa12f7713aaa33df66f8adb69194203944a32d..8e84fc40afabcdafd5b5b6004f78850b8eefd127 100644 (file)
@@ -768,8 +768,10 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     envp=va_arg(ap, XeString *);
     va_end(ap);
     pdata->len=WRITE_APPLICATION_SPAWN(pdata, path, dir, argv, envp);
-    if(pdata->len == SPC_ERROR)
+    if(pdata->len == SPC_ERROR) {
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
+    }
     prot_name=(XeString)"  <-- APPLICATION_SPAWN";
     break;
     }
@@ -929,6 +931,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
   
@@ -940,6 +943,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
   
@@ -958,6 +962,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
       buffer = SPC_Decode_Termios(termios_ptr);
       pdata->len=WRITE_TERMIOS(pdata, connector, side, buffer);
       prot_name=(XeString)"  <-- CHANNEL_TERMIOS";
+      free(buffer);
       break;
     }
 
@@ -965,6 +970,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
 
@@ -1229,8 +1235,10 @@ char **SPC_Get_Multi_Packet(SPC_Connection_Ptr connection,
       if(localprot)
        SPC_Free_Protocol_Ptr(localprot);
       prot=SPC_Filter_Connection(connection, NULL, request, TRUE);
-      if(prot==SPC_ERROR)
-       return(SPC_ERROR);
+      if(prot==SPC_ERROR) {
+        free(out);
+        return(SPC_ERROR);
+      }
       print_protocol_request(name, prot);
       localprot=prot;
       bufptr=PDRP(prot->dataptr);
@@ -1442,6 +1450,8 @@ sscan_application_data(XeString buf,
   *envp=sscan_counted_string(bufptr, &bufptr);
   if(*envp==SPC_ERROR)
     return(SPC_ERROR);
+    
+  return(TRUE);
 }
 
 /*----------------------------------------------------------------------+*/
@@ -1657,7 +1667,7 @@ int SPC_Query_Logfile(SPC_Channel_Ptr channel)
   
   READ_LOGFILE_REPLY(prot->dataptr, &channel->logfile, &junk1, &junk2);
   if (junk1) XeFree(junk1);
-  if (junk1) XeFree(junk2);
+  if (junk2) XeFree(junk2);
                     
   SPC_Free_Protocol_Ptr(prot);
   return (TRUE);
@@ -1811,6 +1821,7 @@ SPC_Validate_User(XeString hostname,
     tt_free (path);
     XeFree(connection_hostname);
     if (logfile) XeFree(logfile);
+    close(open_status);
     return(SPC_ERROR);
   }
   
index 0e54643408587a0021d5142df12630966241da16..47776b468cff156c4c7f307048afaeba933da3ec 100644 (file)
@@ -1598,6 +1598,7 @@ CreateInvocationRecord(
                SET_INV_ERROR(invp->state);
                SET_INV_CANCEL(invp->state);
 
+                close(fd);
                 return invp;
            }    
 
index 0b6e6350fcbf0e6944a98e2969195295d5993954..f8c3b48ff79b3eaeaf2b8922073917430e5e2030 100644 (file)
@@ -446,7 +446,7 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename)
                                        val, _DtACTION_ARG_MODE);
                        _DtSimpleError(DtProgName,DtError, NULL, "%s", buf);
                        free(val);
-                       buf = malloc(_DtAct_MAX_BUF_SIZE);
+                       free(buf);
                        return NULL;
                 }
                break;  /* valid value */
@@ -1027,7 +1027,7 @@ _DtActionConverter(DtDtsDbField * fields,
                sprintf (buf, missingName, _DtACTION_NAME, fileName);
                _DtSimpleError(DtProgName,DtError, NULL, "%s", buf);
                XtFree(fileName);
-               if (buf) XtFree(buf);
+               XtFree(buf);
                _DtSvcProcessUnlock();
                return(True);
        }
index 743212253a9ab023775e85744e9a4e3d94965f7f..f79d1629b1b4e32c681ae6e34ea80c0bf987eb37 100644 (file)
@@ -1393,7 +1393,7 @@ static void
 _DtActMMGetTtMsgInfo(DtDtsMMRecord *actRecp, ActionPtr actp)
 {
        char argNname[ sizeof(_DtACTION_TTN_ARG) /* space for prefix */
-               + 3     /* enough space for three decimal digits */
+               + 9     /* enough space for three decimal digits */
                + sizeof(_DtACTION_TTN_REP_TYPE)]; /* space for longest suffix */
        int  i;
        char *s;
@@ -2165,6 +2165,7 @@ _DtActionFindDBEntry(     ActionRequest *reqp,
                        if ( reqp )
                                SET_TOO_MANY_MAPS(reqp->mask);
                        _DtSvcProcessUnlock();
+                       free(mapto);
                        return NULL;
                }
        }
index 04efe75bde5ac58f8bafbdd8c7393c309a97fcb1..528902c8a88fa3f34c7d6571d83451c7cccddb61 100644 (file)
@@ -484,6 +484,7 @@ dndFileContentsToSelectionValue(
        buf = (void *)XtMalloc(bufLen + 1);
 
        bytesRead = read(fd, buf, bufLen);
+       close(fd);
 
        if (bytesRead == -1 || bytesRead != bufLen) {
                XtFree((char *)buf);
index 1471a6d1b8316eeacd2d913613f1e73386f4424a..cb026c5b2db07c66b6763f16a7be7c7e97ea9b0c 100644 (file)
@@ -155,7 +155,8 @@ extern      int     cde_da_compare(DtDtsMMRecord **entry1, DtDtsMMRecord **entry2);
 extern int     cde_dc_field_compare(DtDtsMMField **entry1, DtDtsMMField **entry2);
 
 
-_DtDtsClear()
+void
+_DtDtsClear(void)
 {
         _DtSvcProcessLock();
        dtdts_path_pattern = 0;
index 156f54e5ad19b497d1ef9cad3fce824d527c659f..0da0fbdd9f887b54e086119753bb803f7163d1ec 100644 (file)
@@ -69,6 +69,7 @@ typedef       int     (*genfunc)(const void *, const void *);
 static DtDtsDbDatabase **db_list;
 static int     num_db = 0;
 
+void
 _DtDtsDbPrintFields(DtDtsDbRecord  *rec_ptr, FILE *fd)
 {
        int             fld;
@@ -84,6 +85,7 @@ _DtDtsDbPrintFields(DtDtsDbRecord  *rec_ptr, FILE *fd)
        }
 }
 
+void
 _DtDtsDbPrintRecords(DtDtsDbDatabase  *db_ptr, FILE *fd)
 {
        int             rec;
index b06605aef84bdde5561a21a94ae9a165302bea97..39707d597cdcfd4c0e3eb1aa6d7b8bd8a95b79aa 100644 (file)
@@ -691,6 +691,7 @@ write_db(DtDtsMMHeader *header, void *index, int size, const char *CacheFile)
                _DtSimpleError(
                        DtProgName, DtError, NULL,
                        (char*) tmpfile, NULL);
+               free(tmpfile);
                return(0);
        }
 
index ef65f04c1750f4fc7ba7e4f2697ceb380a30c251..f6103a4a3dfcae73d19b31b8d10a2200a3d366f1 100644 (file)
@@ -1293,7 +1293,7 @@ _DtWsmSetBackdropSearchPath (
 
            if (postDtEnvironmentString != postDtEnvironmentStringBuf)
            {
-               if (postDtEnvironmentString) XtFree(postDtEnvironmentString);
+               XtFree(postDtEnvironmentString);
                postDtEnvironmentString = NULL;
            }
 
index 51dd61eece572c715a18b1d61639e9631245e5ca..80f65fb4616893cefdbefe962d556b880fbf5656 100644 (file)
@@ -55,6 +55,9 @@ _DtPrintDefaultError(
 {
     _DtPrintDefaultErrorSafe(dpy, event, msg, BUFSIZ);
     /* XXX retval? */
+    
+    /* COV: 87468 nothing actually checks this return value */
+    return(1);
 }
 
 #define _DTP_STRNCAT(s1, s2, nb, ec) \
index d877c3a173987cc3aae855d2595bd7440fe6932c..552261e8ecde45014a85251788e6b57ea7704023 100644 (file)
@@ -33,6 +33,7 @@
  *
  *****************************************************************************/
 
+#include <stdio.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -322,8 +323,8 @@ GetDisplayName (
     /*
      * Create the display name and append it to the current path.
      */
-    (void)strcpy(hostName, display->display_name);
-    (void)strcpy(displayName, display->display_name);
+    snprintf(hostName, sizeof(hostName), "%s", display->display_name);
+    snprintf(displayName, sizeof(displayName), "%s", display->display_name);
     
     /*
      * If this is run to unix or local get the host name - otherwise