From: Peter Howkins Date: Thu, 12 Apr 2018 00:38:02 +0000 (+0100) Subject: lidtsvc: coverity fixes X-Git-Tag: 2.2.4a~89 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=691dffb076e99ad7144649454ae0d8d291b1c397;p=oweals%2Fcde.git lidtsvc: coverity fixes --- diff --git a/cde/lib/DtSvc/DtCodelibs/filegen.C b/cde/lib/DtSvc/DtCodelibs/filegen.C index ad8c8de4..c4a03884 100644 --- a/cde/lib/DtSvc/DtCodelibs/filegen.C +++ b/cde/lib/DtSvc/DtCodelibs/filegen.C @@ -28,6 +28,7 @@ * (c) Copyright 1993, 1994 Sun Microsystems, Inc. * (c) Copyright 1993, 1994 Novell, Inc. */ +#include #include #include #include @@ -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++) { diff --git a/cde/lib/DtSvc/DtEncap/connect.c b/cde/lib/DtSvc/DtEncap/connect.c index 83f1087f..47dd2044 100644 --- a/cde/lib/DtSvc/DtEncap/connect.c +++ b/cde/lib/DtSvc/DtEncap/connect.c @@ -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); diff --git a/cde/lib/DtSvc/DtEncap/noio.c b/cde/lib/DtSvc/DtEncap/noio.c index 409cd4f1..86ee22e3 100644 --- a/cde/lib/DtSvc/DtEncap/noio.c +++ b/cde/lib/DtSvc/DtEncap/noio.c @@ -197,6 +197,7 @@ static char * get_tmp_dir ( if (is_dir_usable (dir)) return (dir); + free(dir); return (NULL); } diff --git a/cde/lib/DtSvc/DtEncap/pipe.c b/cde/lib/DtSvc/DtEncap/pipe.c index 6cf76c91..c3b5f04c 100644 --- a/cde/lib/DtSvc/DtEncap/pipe.c +++ b/cde/lib/DtSvc/DtEncap/pipe.c @@ -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); diff --git a/cde/lib/DtSvc/DtEncap/spc-exec.c b/cde/lib/DtSvc/DtEncap/spc-exec.c index 38889d4c..ac01ccc1 100644 --- a/cde/lib/DtSvc/DtEncap/spc-exec.c +++ b/cde/lib/DtSvc/DtEncap/spc-exec.c @@ -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(); /* diff --git a/cde/lib/DtSvc/DtEncap/spc-net.c b/cde/lib/DtSvc/DtEncap/spc-net.c index 71a5d6da..aa0f5808 100644 --- a/cde/lib/DtSvc/DtEncap/spc-net.c +++ b/cde/lib/DtSvc/DtEncap/spc-net.c @@ -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); } diff --git a/cde/lib/DtSvc/DtEncap/spc-proto.c b/cde/lib/DtSvc/DtEncap/spc-proto.c index 92fa12f7..8e84fc40 100644 --- a/cde/lib/DtSvc/DtEncap/spc-proto.c +++ b/cde/lib/DtSvc/DtEncap/spc-proto.c @@ -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); } diff --git a/cde/lib/DtSvc/DtUtil1/Action.c b/cde/lib/DtSvc/DtUtil1/Action.c index 0e546434..47776b46 100644 --- a/cde/lib/DtSvc/DtUtil1/Action.c +++ b/cde/lib/DtSvc/DtUtil1/Action.c @@ -1598,6 +1598,7 @@ CreateInvocationRecord( SET_INV_ERROR(invp->state); SET_INV_CANCEL(invp->state); + close(fd); return invp; } diff --git a/cde/lib/DtSvc/DtUtil1/ActionDb.c b/cde/lib/DtSvc/DtUtil1/ActionDb.c index 0b6e6350..f8c3b48f 100644 --- a/cde/lib/DtSvc/DtUtil1/ActionDb.c +++ b/cde/lib/DtSvc/DtUtil1/ActionDb.c @@ -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); } diff --git a/cde/lib/DtSvc/DtUtil1/ActionFind.c b/cde/lib/DtSvc/DtUtil1/ActionFind.c index 74321225..f79d1629 100644 --- a/cde/lib/DtSvc/DtUtil1/ActionFind.c +++ b/cde/lib/DtSvc/DtUtil1/ActionFind.c @@ -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; } } diff --git a/cde/lib/DtSvc/DtUtil1/DndFile.c b/cde/lib/DtSvc/DtUtil1/DndFile.c index 04efe75b..528902c8 100644 --- a/cde/lib/DtSvc/DtUtil1/DndFile.c +++ b/cde/lib/DtSvc/DtUtil1/DndFile.c @@ -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); diff --git a/cde/lib/DtSvc/DtUtil1/Dts.c b/cde/lib/DtSvc/DtUtil1/Dts.c index 1471a6d1..cb026c5b 100644 --- a/cde/lib/DtSvc/DtUtil1/Dts.c +++ b/cde/lib/DtSvc/DtUtil1/Dts.c @@ -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; diff --git a/cde/lib/DtSvc/DtUtil1/DtsDb.c b/cde/lib/DtSvc/DtUtil1/DtsDb.c index 156f54e5..0da0fbdd 100644 --- a/cde/lib/DtSvc/DtUtil1/DtsDb.c +++ b/cde/lib/DtSvc/DtUtil1/DtsDb.c @@ -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; diff --git a/cde/lib/DtSvc/DtUtil1/MMDb.c b/cde/lib/DtSvc/DtUtil1/MMDb.c index b06605ae..39707d59 100644 --- a/cde/lib/DtSvc/DtUtil1/MMDb.c +++ b/cde/lib/DtSvc/DtUtil1/MMDb.c @@ -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); } diff --git a/cde/lib/DtSvc/DtUtil2/EnvControl.c b/cde/lib/DtSvc/DtUtil2/EnvControl.c index ef65f04c..f6103a4a 100644 --- a/cde/lib/DtSvc/DtUtil2/EnvControl.c +++ b/cde/lib/DtSvc/DtUtil2/EnvControl.c @@ -1293,7 +1293,7 @@ _DtWsmSetBackdropSearchPath ( if (postDtEnvironmentString != postDtEnvironmentStringBuf) { - if (postDtEnvironmentString) XtFree(postDtEnvironmentString); + XtFree(postDtEnvironmentString); postDtEnvironmentString = NULL; } diff --git a/cde/lib/DtSvc/DtUtil2/PrintXErr.c b/cde/lib/DtSvc/DtUtil2/PrintXErr.c index 51dd61ee..80f65fb4 100644 --- a/cde/lib/DtSvc/DtUtil2/PrintXErr.c +++ b/cde/lib/DtSvc/DtUtil2/PrintXErr.c @@ -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) \ diff --git a/cde/lib/DtSvc/DtUtil2/SmCreateDirs.c b/cde/lib/DtSvc/DtUtil2/SmCreateDirs.c index d877c3a1..552261e8 100644 --- a/cde/lib/DtSvc/DtUtil2/SmCreateDirs.c +++ b/cde/lib/DtSvc/DtUtil2/SmCreateDirs.c @@ -33,6 +33,7 @@ * *****************************************************************************/ +#include #include #include #include @@ -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