From 3cf92f37416b4fcec32ba81b0e5160b55eaca555 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Tue, 24 Apr 2018 02:38:56 +0100 Subject: [PATCH] dtmail: Further Coverity fixes --- cde/programs/dtmail/MotifApp/MainWindow.C | 1 + cde/programs/dtmail/MotifApp/MenuBar.C | 2 +- .../dtmail/dtmail/AlternatesListUiItem.C | 4 ++- cde/programs/dtmail/dtmail/AttachArea.C | 7 ++++ cde/programs/dtmail/dtmail/CheckBoxUiItem.C | 6 ++-- cde/programs/dtmail/dtmail/DmxMessage.C | 5 +++ cde/programs/dtmail/dtmail/DmxPrintOptions.C | 5 +++ cde/programs/dtmail/dtmail/DmxPrintSetup.C | 2 +- cde/programs/dtmail/dtmail/Editor.C | 11 +++--- cde/programs/dtmail/dtmail/MsgScrollingList.C | 2 +- cde/programs/dtmail/dtmail/OptCmd.C | 2 +- cde/programs/dtmail/dtmail/RoamApp.C | 2 +- cde/programs/dtmail/dtmail/RoamCmds.C | 22 +++++++----- cde/programs/dtmail/dtmail/RoamMenuWindow.C | 6 ++-- cde/programs/dtmail/dtmail/SendMsgDialog.C | 10 +++--- cde/programs/dtmail/dtmail/Sort.C | 2 +- cde/programs/dtmail/dtmail/dtb_utils.C | 9 +++-- cde/programs/dtmail/dtmailpr/utils.C | 1 + cde/programs/dtmail/include/DtMail/DtMail.hh | 2 +- cde/programs/dtmail/libDtMail/Common/Buffer.C | 2 ++ .../dtmail/libDtMail/Common/DtMailRc.C | 8 ++--- .../dtmail/libDtMail/Common/POP3Server.C | 6 ++-- .../dtmail/libDtMail/RFC/MIMEBodyPart.C | 32 ++++++++--------- .../dtmail/libDtMail/RFC/RFCMailBox.C | 16 ++++----- .../dtmail/libDtMail/RFC/RFCMailValues.C | 2 +- .../dtmail/libDtMail/RFC/V3BodyPart.C | 35 +++++++++---------- 26 files changed, 114 insertions(+), 88 deletions(-) diff --git a/cde/programs/dtmail/MotifApp/MainWindow.C b/cde/programs/dtmail/MotifApp/MainWindow.C index 25b184aa..2fa55e4c 100644 --- a/cde/programs/dtmail/MotifApp/MainWindow.C +++ b/cde/programs/dtmail/MotifApp/MainWindow.C @@ -110,6 +110,7 @@ MainWindow::MainWindow( char *name, Boolean allowResize ) : UIComponent ( name ) _last_state = 0; _flash_owin = 0; _flash_iwin = 0; + _main = NULL; memset(&_window_attributes, 0, sizeof(XWindowAttributes)); assert ( theApplication != NULL ); // Application object must exist diff --git a/cde/programs/dtmail/MotifApp/MenuBar.C b/cde/programs/dtmail/MotifApp/MenuBar.C index be61fb6b..1a7f60f3 100644 --- a/cde/programs/dtmail/MotifApp/MenuBar.C +++ b/cde/programs/dtmail/MotifApp/MenuBar.C @@ -260,7 +260,7 @@ MenuBar::createPulldown ( } XtManageChildren ( head_wl, num_wl ); - delete head_wl; + delete [] head_wl; return(pulldown); } diff --git a/cde/programs/dtmail/dtmail/AlternatesListUiItem.C b/cde/programs/dtmail/dtmail/AlternatesListUiItem.C index 6d7b334f..0a802a28 100644 --- a/cde/programs/dtmail/dtmail/AlternatesListUiItem.C +++ b/cde/programs/dtmail/dtmail/AlternatesListUiItem.C @@ -179,8 +179,10 @@ void AlternatesListUiItem::writeFromSourceToUi() list_str = strdup(""); } - if ((buf = (char *) malloc(strlen(list_str) + 1)) == NULL) + if ((buf = (char *) malloc(strlen(list_str) + 1)) == NULL) { + free((void *) list_str); return; + } strcpy(buf, (char *)list_str); if((token = (char *) strtok(buf, " "))) diff --git a/cde/programs/dtmail/dtmail/AttachArea.C b/cde/programs/dtmail/dtmail/AttachArea.C index b0999008..29764ec8 100644 --- a/cde/programs/dtmail/dtmail/AttachArea.C +++ b/cde/programs/dtmail/dtmail/AttachArea.C @@ -188,6 +188,10 @@ AttachArea::AttachArea ( _editCmdList = NULL; _size_selected_label = NULL; _format_button = NULL; + _descriptionDialog = NULL; + _no_attachments_label = NULL; + _attachments_label = NULL; + _size_attachments_label = NULL; } @@ -702,6 +706,9 @@ AttachArea::addAttachment( if (read(fd, buffer, (unsigned int) s.st_size) < 0) { SafeClose(fd); + delete [] buf; + delete [] buffer; + delete [] errormsg; return(NULL); } buffer[s.st_size] = 0; diff --git a/cde/programs/dtmail/dtmail/CheckBoxUiItem.C b/cde/programs/dtmail/dtmail/CheckBoxUiItem.C index c6053021..c3150ced 100644 --- a/cde/programs/dtmail/dtmail/CheckBoxUiItem.C +++ b/cde/programs/dtmail/dtmail/CheckBoxUiItem.C @@ -92,10 +92,10 @@ void CheckBoxUiItem::writeFromSourceToUi() // // This assumes that a non-null value means that the // value is set and that a non-null means turn on the CB - if (strcmp(value, "") == 0) - options_checkbox_set_value(w, TRUE, this->dirty_bit); - else if (NULL == value || strcmp(value, "f") == 0) + if (NULL == value || strcmp(value, "f") == 0) options_checkbox_set_value(w, FALSE, this->dirty_bit); + else if (strcmp(value, "") == 0) + options_checkbox_set_value(w, TRUE, this->dirty_bit); free((void*) value); } diff --git a/cde/programs/dtmail/dtmail/DmxMessage.C b/cde/programs/dtmail/dtmail/DmxMessage.C index 0c6ed6e6..803fe739 100644 --- a/cde/programs/dtmail/dtmail/DmxMessage.C +++ b/cde/programs/dtmail/dtmail/DmxMessage.C @@ -95,6 +95,11 @@ DmxMsg::DmxMsg (void) addlInfo = NULL; numBPs = 0; cachedValues = DTM_FALSE; + msgHandle = NULL; + msgHeader.header_values = 0; + msgHeader.number_of_names = 0; + bodyParts = NULL; + isNew = DTM_FALSE; return; } diff --git a/cde/programs/dtmail/dtmail/DmxPrintOptions.C b/cde/programs/dtmail/dtmail/DmxPrintOptions.C index 18d1ca0a..bdfef8fe 100644 --- a/cde/programs/dtmail/dtmail/DmxPrintOptions.C +++ b/cde/programs/dtmail/dtmail/DmxPrintOptions.C @@ -218,6 +218,11 @@ DmxPrintOptions::DmxPrintOptions ( _propui_array_iterator = 0; _parent = parent; _prop_source = NULL; + _hdrftr_frame = NULL; + _margin_frame = NULL; + _msgsep_iom = NULL; + _prthdr_iom = NULL; + // // Create form to hold the printing options diff --git a/cde/programs/dtmail/dtmail/DmxPrintSetup.C b/cde/programs/dtmail/dtmail/DmxPrintSetup.C index 8aa00e69..ea042dbb 100644 --- a/cde/programs/dtmail/dtmail/DmxPrintSetup.C +++ b/cde/programs/dtmail/dtmail/DmxPrintSetup.C @@ -116,7 +116,7 @@ DmxPrintSetup::DmxPrintSetup ( _filename = (char*) malloc(MAXPATHLEN+1); if (NULL != _filename) - sprintf(_filename, "%s/dtmail_messages.ps", getenv("HOME")); + snprintf(_filename, MAXPATHLEN+1, "%s/dtmail_messages.ps", getenv("HOME")); _printCB = printCB; _cancelCB = cancelCB; diff --git a/cde/programs/dtmail/dtmail/Editor.C b/cde/programs/dtmail/dtmail/Editor.C index 6dc80ced..ada200ea 100644 --- a/cde/programs/dtmail/dtmail/Editor.C +++ b/cde/programs/dtmail/dtmail/Editor.C @@ -254,10 +254,10 @@ Editor::set_message(DtMail::Message * msg, } bp->unlockContents(error); firstBPHandled = DTM_TRUE; - if (attr) { - DtDtsFreeAttributeValue(attr); - attr = NULL; - } + } + if (attr) { + DtDtsFreeAttributeValue(attr); + attr = NULL; } free(type); @@ -424,8 +424,7 @@ Editor::update_display_from_props(void) value = strdup("24"); } rows = (int) strtol(value, NULL, 10); - if (NULL != value) - free((void*) value); + free((void*) value); set_rows(rows); // If toolcols is set, overwrite the column width with "toolcols" value. diff --git a/cde/programs/dtmail/dtmail/MsgScrollingList.C b/cde/programs/dtmail/dtmail/MsgScrollingList.C index 600615b8..1953188d 100644 --- a/cde/programs/dtmail/dtmail/MsgScrollingList.C +++ b/cde/programs/dtmail/dtmail/MsgScrollingList.C @@ -2436,7 +2436,7 @@ MsgScrollingList::updateListItems(int current, fprintf(stderr, "dtmail: getMessageSummary: Couldn't get summary for msg # %d\n", m); - if ((msg == NULL) || (mbox == NULL)) + if (msg == NULL) { // Error ; diff --git a/cde/programs/dtmail/dtmail/OptCmd.C b/cde/programs/dtmail/dtmail/OptCmd.C index 7e0dc716..74024a45 100644 --- a/cde/programs/dtmail/dtmail/OptCmd.C +++ b/cde/programs/dtmail/dtmail/OptCmd.C @@ -161,7 +161,7 @@ OptCmd::OptCmd ( char *name, char *label, int active, Widget parent) : generalDialog = NULL; _PrintingOptions = NULL; _MailRetrievalOptions = NULL; - + printing_pane_list = NULL; } void diff --git a/cde/programs/dtmail/dtmail/RoamApp.C b/cde/programs/dtmail/dtmail/RoamApp.C index 647fc4e3..59e23aeb 100644 --- a/cde/programs/dtmail/dtmail/RoamApp.C +++ b/cde/programs/dtmail/dtmail/RoamApp.C @@ -511,7 +511,7 @@ static char *tooltalk_save_buffer_to_file( char *tmpdir = new char[MAXPATHLEN+1]; // 1. Get buffer content into file. - sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); + snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); p = tempnam(tmpdir, "mail"); if (p == NULL) { diff --git a/cde/programs/dtmail/dtmail/RoamCmds.C b/cde/programs/dtmail/dtmail/RoamCmds.C index 666d32b2..f43d4a58 100644 --- a/cde/programs/dtmail/dtmail/RoamCmds.C +++ b/cde/programs/dtmail/dtmail/RoamCmds.C @@ -540,7 +540,7 @@ ConvertContainerCmd::post_dialog() char * buf = new char[25]; - sprintf(buf, "Converted: %3d%", 0); + sprintf(buf, "Converted: %3d%%", 0); _dialog->post ("Mailer", buf, @@ -1660,7 +1660,7 @@ MoveCopyCmd::fileSelectedCallback2 ( // If a string was successfully extracted, call // unifiedMailboxSelected to handle the file. *selected = '\0'; - if (NULL != dname) strcat(selected, dname); + if (NULL != dname) snprintf(selected, sizeof(selected), "%s", dname); strcat(selected, fname); obj->updateUnifiedData(); obj->unifiedMailboxSelected( @@ -1852,7 +1852,7 @@ PrintCmd::printit( int silent ) DebugPrintf(1, "%s: printit\n", name()); // Create tmp file. - sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); + snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); if ((p = tempnam(tmpdir, "dtmail")) == NULL) { delete [] tmpdir; return; @@ -2471,9 +2471,9 @@ SaveAsTextCmd::writeTextFromScrolledList(int fd) // Create temp file. // char *tmpdir = new char[MAXPATHLEN+1]; - sprintf(tmpdir, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); + snprintf(tmpdir, MAXPATHLEN+1, "%s/%s", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY); if ((tmppath = tempnam(tmpdir, "dtmail")) == NULL) { - sprintf(buf, GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir); + snprintf(buf, sizeof(buf), GETMSG(DT_catd, 3, 51, "Unable to create %s."), tmpdir); _genDialog->setToErrorDialog(GETMSG(DT_catd, 3, 52, "Mailer"), buf); helpId = DTMAILHELPNOCREATE; _genDialog->post_and_return(helpId); @@ -3393,7 +3393,7 @@ VacationCmd::stopVacation() { char *forwardfile = new char[MAXPATHLEN+1]; - sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile); + snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile); // Remove the current .forward file (it has vacation in it) // Recover and replace the original backup forward file, if @@ -3414,7 +3414,7 @@ VacationCmd::priorVacationRunning() Boolean retval = FALSE; char *forwardfile = new char[MAXPATHLEN+1]; - sprintf(forwardfile, "%s/%s", getenv("HOME"), _forwardFile); + snprintf(forwardfile, MAXPATHLEN+1, "%s/%s", getenv("HOME"), _forwardFile); if (SafeAccess(forwardfile, F_OK) != 0) { delete [] forwardfile; @@ -3732,6 +3732,7 @@ VacationCmd::handleForwardFile() delete [] messagefile; delete [] error_buf; delete [] forwardfile; + SafeClose(bkup_fd); SafeClose(fwd_fd); return 1; } @@ -3754,6 +3755,7 @@ VacationCmd::handleForwardFile() strlen(append_buf2)) { // error SafeClose(bkup_fd); + SafeClose(fwd_fd); delete [] buf; delete [] messagefile; delete [] error_buf; @@ -3831,7 +3833,7 @@ VacationCmd::recoverForwardFile( return(-1); } - if ((fd = SafeOpen(file, O_RDONLY)) == 0) { + if ((fd = SafeOpen(file, O_RDONLY)) == -1) { delete [] buf; return(-1); } @@ -3935,8 +3937,10 @@ VacationCmd::parseVacationMessage() size_t map_size = (int) (buf.st_size + (page_size - (buf.st_size % page_size))); - if (buf.st_size == 0) + if (buf.st_size == 0) { + SafeClose(fd); return; + } int free_buf = 0; mbuf.size = buf.st_size; diff --git a/cde/programs/dtmail/dtmail/RoamMenuWindow.C b/cde/programs/dtmail/dtmail/RoamMenuWindow.C index c0b7357a..cd857ee7 100644 --- a/cde/programs/dtmail/dtmail/RoamMenuWindow.C +++ b/cde/programs/dtmail/dtmail/RoamMenuWindow.C @@ -465,7 +465,7 @@ RoamMenuWindow::RoamMenuWindow (char *name) : MenuWindow ("dtmail", True) _last_sorted_by = (SortBy) atoi(value); free((void*) value); - if (NULL != buffer) XtFree(buffer); + XtFree(buffer); } @@ -4248,6 +4248,8 @@ RoamMenuWindow::syncViewAndStoreCallback( RoamMenuWindow * rmw = (RoamMenuWindow *)client_data; bval = rmw->syncViewAndStore(op, path, args); + + va_end(args); return(bval); } @@ -5113,7 +5115,7 @@ RoamMenuWindow::inList(char *filename, DtVirtArray *list) for (int i=0; i < list->length(); i++) { cmd = (*list)[i]; - if (strcmp(filename, cmd->containerName()) == 0) + if (filename && strcmp(filename, cmd->containerName()) == 0) return(i); } return(-1); diff --git a/cde/programs/dtmail/dtmail/SendMsgDialog.C b/cde/programs/dtmail/dtmail/SendMsgDialog.C index a00187eb..5e563edb 100644 --- a/cde/programs/dtmail/dtmail/SendMsgDialog.C +++ b/cde/programs/dtmail/dtmail/SendMsgDialog.C @@ -461,7 +461,7 @@ SendMsgDialog::updateMsgHnd() { DtMailEnv error; DtMail::Envelope * env; - int textLen; + int textLen = 0; env = _msgHandle->getEnvelope(error); storeHeaders(); @@ -472,9 +472,9 @@ SendMsgDialog::updateMsgHnd() XtFree(widget_text); widget_text = NULL; } - else - textLen = strlen(widget_text); - + else if(widget_text) { + textLen = strlen(widget_text); + } // Even if textlen is 0 because user has cleared all previous text, // need to setContents again to clear first BP. Otherwise, deleted // text will show up. @@ -3150,7 +3150,7 @@ SendMsgDialog::parseNplace(const char * path) if (SafeRead(fd, _dead_letter_buf, (unsigned int) buf.st_size) != buf.st_size) { - delete _dead_letter_buf; + delete [] _dead_letter_buf; close(fd); return; } diff --git a/cde/programs/dtmail/dtmail/Sort.C b/cde/programs/dtmail/dtmail/Sort.C index 2f676c00..d7ee6de1 100644 --- a/cde/programs/dtmail/dtmail/Sort.C +++ b/cde/programs/dtmail/dtmail/Sort.C @@ -355,7 +355,7 @@ Sort::sortMessages(MsgScrollingList *displayList, } // Now cleanup. - delete messages; + delete [] messages; } // diff --git a/cde/programs/dtmail/dtmail/dtb_utils.C b/cde/programs/dtmail/dtmail/dtb_utils.C index 04f80303..8b8ee584 100644 --- a/cde/programs/dtmail/dtmail/dtb_utils.C +++ b/cde/programs/dtmail/dtmail/dtb_utils.C @@ -3054,11 +3054,10 @@ determine_exe_dir( if (path_prefix != NULL) { char *abs_exe_dir = new char[MAXPATHLEN+1]; - strcpy(abs_exe_dir, path_prefix); - if (strcmp(buf, ".") != 0) - { - strcat(abs_exe_dir, "/"); - strcat(abs_exe_dir, buf); + if (strcmp(buf, ".") != 0) { + snprintf(abs_exe_dir, MAXPATHLEN+1, "%s/%s", path_prefix, buf); + } else { + snprintf(abs_exe_dir, MAXPATHLEN+1, "%s", path_prefix); } strcpy(buf, abs_exe_dir); delete [] abs_exe_dir; diff --git a/cde/programs/dtmail/dtmailpr/utils.C b/cde/programs/dtmail/dtmailpr/utils.C index 9ce88c08..2fb2f122 100644 --- a/cde/programs/dtmail/dtmailpr/utils.C +++ b/cde/programs/dtmail/dtmailpr/utils.C @@ -140,6 +140,7 @@ formatHeader (DtMailHeaderLine &info, enum DmxHeaderType htype) break; case NUMHDRTYPES: default: + delete [] fbuf; return ""; } return (fbuf); //need to free this after using it diff --git a/cde/programs/dtmail/include/DtMail/DtMail.hh b/cde/programs/dtmail/include/DtMail/DtMail.hh index f326b506..89f6c47d 100644 --- a/cde/programs/dtmail/include/DtMail/DtMail.hh +++ b/cde/programs/dtmail/include/DtMail/DtMail.hh @@ -464,7 +464,7 @@ class DtMail { void freerawlist(char **argv); char *mt_value(char name[]); char *expand(char *); - int getfolderdir(char *); + int getfolderdir(char *, size_t); static int hash(char *name); static void vfree(char *cp); diff --git a/cde/programs/dtmail/libDtMail/Common/Buffer.C b/cde/programs/dtmail/libDtMail/Common/Buffer.C index 13fec632..5c92aede 100644 --- a/cde/programs/dtmail/libDtMail/Common/Buffer.C +++ b/cde/programs/dtmail/libDtMail/Common/Buffer.C @@ -236,6 +236,8 @@ BufferMemory::iterate(Buffer::CallBack callback, ...) // check for problems if (ret) break; } + + va_end(va); return (ret); } diff --git a/cde/programs/dtmail/libDtMail/Common/DtMailRc.C b/cde/programs/dtmail/libDtMail/Common/DtMailRc.C index 14df67bd..ddf2550b 100644 --- a/cde/programs/dtmail/libDtMail/Common/DtMailRc.C +++ b/cde/programs/dtmail/libDtMail/Common/DtMailRc.C @@ -1986,16 +1986,16 @@ void DtMail::MailRc::add_alternates(char *name) * Determine the current folder directory name. */ int -DtMail::MailRc::getfolderdir(char *name) +DtMail::MailRc::getfolderdir(char *name, size_t buffsize) { char *folder; if ((folder = mt_value("folder")) == NOSTR) return(-1); if (*folder == '/') - strcpy(name, folder); + snprintf(name, buffsize, "%s", folder); else - sprintf(name, "%s/%s", mt_value("HOME"), folder); + snprintf(name, buffsize, "%s/%s", mt_value("HOME"), folder); return(0); } @@ -2017,7 +2017,7 @@ DtMail::MailRc::expand(char *name) struct stat sbuf; char *retchr = NULL; - if (name[0] == '+' && getfolderdir(cmdbuf) >= 0) { + if (name[0] == '+' && getfolderdir(cmdbuf, LINESIZE) >= 0) { sprintf(xname, "%s/%s", cmdbuf, name + 1); str = expand(xname); delete [] xname; diff --git a/cde/programs/dtmail/libDtMail/Common/POP3Server.C b/cde/programs/dtmail/libDtMail/Common/POP3Server.C index bb93b31a..d87cf468 100644 --- a/cde/programs/dtmail/libDtMail/Common/POP3Server.C +++ b/cde/programs/dtmail/libDtMail/Common/POP3Server.C @@ -486,8 +486,9 @@ POP3Server::uidlist_read(DtVirtArray *uidlist) while (NULL != fgets(uidliststr, DTMAS_POPBUFSIZE, fp)) if (sscanf(uidliststr, "%d %s", &curmsg, curuidstr) == 2) uidlist->append(strdup(uidliststr)); + + fclose(fp); } - fclose(fp); } void @@ -506,7 +507,6 @@ POP3Server::uidlist_write(DtVirtArray *uidlist) uidliststr = (*uidlist)[i]; fprintf(fp, "%s\n", uidliststr); } + fclose(fp); } - fclose(fp); - } diff --git a/cde/programs/dtmail/libDtMail/RFC/MIMEBodyPart.C b/cde/programs/dtmail/libDtMail/RFC/MIMEBodyPart.C index f352cadf..df1cae5c 100644 --- a/cde/programs/dtmail/libDtMail/RFC/MIMEBodyPart.C +++ b/cde/programs/dtmail/libDtMail/RFC/MIMEBodyPart.C @@ -267,24 +267,24 @@ MIMEBodyPart::getContentType(DtMailEnv &error, char **mime_type) { DtMailValueSeq value; - if (mime_type) - *mime_type = (char *)0; + if (mime_type) { + *mime_type = (char *)0; - if (_body_env) - _body_env->getHeader(error, "Content-Type", DTM_FALSE, value); + if (_body_env) { + _body_env->getHeader(error, "Content-Type", DTM_FALSE, value); + } - if (_body_env && !error.isSet()) - { - // Handle "Content-Type: text" problem with /usr/lib/mail.local - if (strcasecmp(*(value[0]), "text")==0) - *mime_type = strdup("text/plain"); - else - *mime_type = strdup(*(value[0])); - } - else - { - error.clear(); - *mime_type = strdup("text/plain"); + if (_body_env && !error.isSet()) { + // Handle "Content-Type: text" problem with /usr/lib/mail.local + if (strcasecmp(*(value[0]), "text")==0) { + *mime_type = strdup("text/plain"); + } else { + *mime_type = strdup(*(value[0])); + } + } else { + error.clear(); + *mime_type = strdup("text/plain"); + } } } diff --git a/cde/programs/dtmail/libDtMail/RFC/RFCMailBox.C b/cde/programs/dtmail/libDtMail/RFC/RFCMailBox.C index 3b0b98e3..309e0ec7 100644 --- a/cde/programs/dtmail/libDtMail/RFC/RFCMailBox.C +++ b/cde/programs/dtmail/libDtMail/RFC/RFCMailBox.C @@ -168,7 +168,7 @@ extern "C" ssize_t pread(int, void *, size_t, off_t); #endif #define GET_DUMPFILE_NAME(dfn) \ - sprintf(dfn, "%s/%s/dtmail.dump", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY) + snprintf(dfn, sizeof(dfn), "%s/%s/dtmail.dump", getenv("HOME"), DtPERSONAL_TMP_DIRECTORY) /* * Local Data Definitions @@ -216,7 +216,7 @@ void HexDump(FILE *pfp, char *pmsg, unsigned char *pbufr, int plen, int plimit) return; if (pfp_r == (FILE*) NULL) { - char *dumpfilename = new char [MAXPATHLEN+1]; + char dumpfilename[MAXPATHLEN+1]; _Xctimeparams ctime_buf; GET_DUMPFILE_NAME(dumpfilename); @@ -225,7 +225,6 @@ void HexDump(FILE *pfp, char *pmsg, unsigned char *pbufr, int plen, int plimit) memset((void*) &ctime_buf, 0, sizeof(_Xctimeparams)); fprintf(pfp_r, "--------------------- pid=%ld %s", (long)getpid(), _XCtime(&clockTime, ctime_buf)); - delete [] dumpfilename; } (void) fprintf(pfp_r, "--> %s (%d bytes at %p):\n", pmsg, plen, pbufr); @@ -2042,6 +2041,9 @@ RFCMailBox::mapFile(DtMailEnv & error, } error.setError(DTME_NoMemory); delete map; +#if !defined(DO_ANONYMOUS_MAP) + SafeClose(fd); +#endif return(-1); } @@ -4506,7 +4508,7 @@ void RFCMailBox::writeToDumpFile(const char *format, ...) { DtMailEnv error; - char *dumpfilename = new char[MAXPATHLEN+1]; + char dumpfilename[MAXPATHLEN+1]; _Xctimeparams ctime_buf; GET_DUMPFILE_NAME(dumpfilename); @@ -4524,8 +4526,7 @@ RFCMailBox::writeToDumpFile(const char *format, ...) fprintf(df, "---------------------\n"); fprintf(df, "\n\n"); - - delete [] dumpfilename; + fclose(df); } @@ -4558,7 +4559,7 @@ RFCMailBox::dumpMaps(const char *str) DtMailEnv error; off_t total_file_size = 0; struct sigaction sig_act, old_sig_act; - char *dumpfilename = new char[MAXPATHLEN+1]; + char dumpfilename[MAXPATHLEN+1]; GET_DUMPFILE_NAME(dumpfilename); FILE *df = fopen(dumpfilename, "a"); @@ -4567,7 +4568,6 @@ RFCMailBox::dumpMaps(const char *str) error.logError( DTM_FALSE, "dumpMaps(): Cant open dump file %s\n", dumpfilename); - delete [] dumpfilename; if (SafeFStat(_fd, &buf) < 0) { fprintf(df, "dumpMaps(): fstat(%d) failed errno=%d\n", _fd, errno); diff --git a/cde/programs/dtmail/libDtMail/RFC/RFCMailValues.C b/cde/programs/dtmail/libDtMail/RFC/RFCMailValues.C index c6c23134..46e7fac3 100644 --- a/cde/programs/dtmail/libDtMail/RFC/RFCMailValues.C +++ b/cde/programs/dtmail/libDtMail/RFC/RFCMailValues.C @@ -153,7 +153,7 @@ decode1522(const char * enc_start, const char * max_end, char **output, DtMail:: default: // Invalid encoding. Assume a false match. - if (cs_name != NULL) free(cs_name); + free(cs_name); return (enc_start); } diff --git a/cde/programs/dtmail/libDtMail/RFC/V3BodyPart.C b/cde/programs/dtmail/libDtMail/RFC/V3BodyPart.C index 425f640a..dd043ebd 100644 --- a/cde/programs/dtmail/libDtMail/RFC/V3BodyPart.C +++ b/cde/programs/dtmail/libDtMail/RFC/V3BodyPart.C @@ -346,24 +346,23 @@ V3BodyPart::getContentType(DtMailEnv &error, char **v3_type) MutexLock dt_lib_lock(_DtMutex); DtMailValueSeq value; - if (v3_type) - *v3_type = (char *)0; - - _body_env->getHeader(error, "Content-Type", DTM_FALSE, value); - if (error.isNotSet()) - *v3_type = strdup(*(value[0])); - else - { - error.clear(); - value.clear(); - _body_env->getHeader(error, "X-Sun-Data-Type", DTM_FALSE, value); - if (error.isNotSet()) - *v3_type = strdup(*(value[0])); - else - { - error.clear(); - *v3_type = strdup("text"); - } + if (v3_type) { + *v3_type = (char *)0; + + _body_env->getHeader(error, "Content-Type", DTM_FALSE, value); + if (error.isNotSet()) { + *v3_type = strdup(*(value[0])); + } else { + error.clear(); + value.clear(); + _body_env->getHeader(error, "X-Sun-Data-Type", DTM_FALSE, value); + if (error.isNotSet()) { + *v3_type = strdup(*(value[0])); + } else { + error.clear(); + *v3_type = strdup("text"); + } + } } } -- 2.25.1