From: Peter Howkins Date: Wed, 4 Apr 2018 18:48:23 +0000 (+0100) Subject: libdtterm: Resolve coverity issues X-Git-Tag: 2.2.4a~130 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ccab0597ed51ef1540b1750546b2fc1386ab32b8;p=oweals%2Fcde.git libdtterm: Resolve coverity issues --- diff --git a/cde/lib/DtTerm/TermPrim/TermPrim.c b/cde/lib/DtTerm/TermPrim/TermPrim.c index f9859aba..fe9e98a5 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrim.c +++ b/cde/lib/DtTerm/TermPrim/TermPrim.c @@ -1227,7 +1227,7 @@ Initialize(Widget ref_w, Widget w, Arg *args, Cardinal *num_args) tpd->boldTermFont = _DtTermPrimRenderFontCreate(w, tw->term.boldFont); } - if (fontName) XFree(fontName) ; + XFree(fontName) ; } } } @@ -1569,7 +1569,7 @@ InitOrResizeTermBuffer(Widget w) ** we ran out of memory, no need try and resize the ** term buffer */ - resizeTermBuffer == False; + resizeTermBuffer = False; } } @@ -1893,7 +1893,6 @@ handleNonMaskableEvents(Widget w, XtPointer eventData, XEvent *event, { DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w; DtTermPrimData tpd = tw->term.tpd; - unsigned char *buffer = (unsigned char *) 0; int fd = tw->term.pty; switch (event->type) { @@ -1925,11 +1924,6 @@ handleNonMaskableEvents(Widget w, XtPointer eventData, XEvent *event, /* reinstall the pty input select... */ (void) _DtTermPrimStartOrStopPtyInput(w); - - /* free the old buffer... */ - if (buffer) { - (void) XtFree((char *) buffer); - } if ((tpd->scroll.nojump.pendingScroll == 0) && !moreInput(tw->term.pty)) { @@ -2306,6 +2300,7 @@ _mergeEnv if (newEnv == NULL) { printf("L10n MALLOC ERROR\n"); + return NULL; } /* @@ -3749,8 +3744,7 @@ _DtTermPrimPutEnv(char *c1, char *c2) char buffer[BUFSIZ]; char *c; - (void) strcpy(buffer, c1); - (void) strcat(buffer, c2); + snprintf(buffer, sizeof(buffer), "%s%s", c1, c2); c = XtMalloc(strlen(buffer) + 1); (void) strcpy(c, buffer); (void) putenv(c); diff --git a/cde/lib/DtTerm/TermPrim/TermPrimBufferWc.c b/cde/lib/DtTerm/TermPrim/TermPrimBufferWc.c index 58b665e3..b3dd9dda 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimBufferWc.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimBufferWc.c @@ -257,7 +257,7 @@ _countWidth ** its a null character, but is still has a width for our ** purposes... */ - charWidth == 1; + charWidth = 1; break; default: break; diff --git a/cde/lib/DtTerm/TermPrim/TermPrimGetPty-svr4.c b/cde/lib/DtTerm/TermPrim/TermPrimGetPty-svr4.c index 5f79d298..a9397566 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimGetPty-svr4.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimGetPty-svr4.c @@ -283,8 +283,16 @@ SetupPty(char *ptySlave, int ptyFd) #else /* linux */ - chown(ptySlave, getuid(), getgid()); - chmod(ptySlave, 0622); + if(chown(ptySlave, getuid(), getgid()) == -1) { + (void) perror("Error performing chown()"); + /* exit the subprocess */ + return(1); + } + if(chmod(ptySlave, 0622) == -1) { + (void) perror("Error performing chmod()"); + /* exit the subprocess */ + return(1); + } #endif /* linux */ /* success... */ diff --git a/cde/lib/DtTerm/TermPrim/TermPrimSelect.c b/cde/lib/DtTerm/TermPrim/TermPrimSelect.c index 24f5e8e8..d352d1d4 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimSelect.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimSelect.c @@ -787,7 +787,7 @@ setSelection selectColEnd = (selectInfo->end - 1) % (selectInfo->columns + 1); DebugF('c', 1, - fprintf(stderr, "set selection units: %d-%d lines: %d-%d\n", + fprintf(stderr, "set selection units: %ld-%ld lines: %d-%d\n", selectInfo->begin, selectInfo->end, selectLineBegin, selectLineEnd)); @@ -2952,6 +2952,8 @@ _DtTermPrimSelectPasteClipboard if (malloc_size != 0) XtFree(total_tmp_value); (void) _DtTermPrimCursorOn(w); + + return True; } /* This is the event interface for paste clipboard */ diff --git a/cde/lib/DtTerm/TermPrim/TermPrimSetPty.c b/cde/lib/DtTerm/TermPrim/TermPrimSetPty.c index 6f496fbe..15f43296 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimSetPty.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimSetPty.c @@ -380,7 +380,6 @@ _DtTermPrimPtyGetDefaultModes() /* we got a valid reference tty... */ DebugF('p', 3, fprintf(stderr, ">>_DtTermPrimPtyGetDefaultModes() valid reference \"/dev/tty\"\n")); - refTty = tty; refValid = 1; } } diff --git a/cde/lib/DtTerm/TermPrim/TermPrimSetUtmp.c b/cde/lib/DtTerm/TermPrim/TermPrimSetUtmp.c index 211fd2ab..7b47a695 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimSetUtmp.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimSetUtmp.c @@ -411,8 +411,8 @@ UtmpEntryCreate(Widget w, pid_t pid, char *utmpLine) utPtr->ut_exit.e_exit = 2; #endif - (void) strncpy(utPtr->ut_user, (userName && *userName) ? userName : "????", - sizeof(utPtr->ut_user)); + snprintf(utPtr->ut_user, sizeof(utPtr->ut_user), + "%s", (userName && *userName) ? userName : "????"); (void) strncpy(utPtr->ut_line, utmpLine, sizeof(utPtr->ut_line)); utPtr->ut_pid = pid; (void) time(&now); @@ -529,7 +529,7 @@ UtmpEntryDestroy(Widget w, char *utmpLine) time_t now; ut.ut_type = USER_PROCESS; - (void) strncpy(ut.ut_line, utmpLine, sizeof(ut.ut_line)); + snprintf(ut.ut_line, sizeof(ut.ut_line), "%s", utmpLine); (void) setutent(); if (utPtr = getutline(&ut)) { utPtr->ut_type = DEAD_PROCESS; diff --git a/cde/lib/DtTerm/TermPrim/TermPrimUtil.c b/cde/lib/DtTerm/TermPrim/TermPrimUtil.c index 6429ecaf..88657572 100644 --- a/cde/lib/DtTerm/TermPrim/TermPrimUtil.c +++ b/cde/lib/DtTerm/TermPrim/TermPrimUtil.c @@ -620,7 +620,7 @@ _DtTermPrimLogFileCleanup for (logInfoTmp = logInfoHead->next; logInfoTmp; logInfoTmp = logInfoTmp->next) { DebugF('s', 10, fprintf(stderr, - ">>flushing logfile 0x%lx\n", logInfoTmp->logFile)); + ">>flushing logfile %p\n", logInfoTmp->logFile)); (void) fflush(logInfoTmp->logFile); } _DtTermProcessUnlock(); diff --git a/cde/lib/DtTerm/TermView/TermView.c b/cde/lib/DtTerm/TermView/TermView.c index 63c35af7..57f16f03 100644 --- a/cde/lib/DtTerm/TermView/TermView.c +++ b/cde/lib/DtTerm/TermView/TermView.c @@ -1696,7 +1696,7 @@ GeometryManager(Widget child, XtWidgetGeometry *desired, c = ""; } - (void) printf("GeometryManager: %s widget (0x%lx) requesting geo change\n", + (void) printf("GeometryManager: %s widget (%p) requesting geo change\n", c, child); return(XtGeometryNo); diff --git a/cde/lib/DtTerm/TermView/TermViewMenu.c b/cde/lib/DtTerm/TermView/TermViewMenu.c index f10484d5..858adf4c 100644 --- a/cde/lib/DtTerm/TermView/TermViewMenu.c +++ b/cde/lib/DtTerm/TermView/TermViewMenu.c @@ -367,7 +367,7 @@ createSizeMenu } /* get a mnemonic for "Default"... */ - (void) strcpy(buffer, (GETMESSAGE(NL_SETN_ViewMenu,1, "Default"))); + snprintf(buffer, sizeof(buffer), "%s", (GETMESSAGE(NL_SETN_ViewMenu,1, "Default"))); #ifdef NOTDEF for (c2 = buffer; *c2; c2++) { if (!strchr(mnemonics, *c2) && !isspace(*c2)) @@ -575,7 +575,7 @@ createFontMenu 0, NULL, NULL, fontChangeCallback, (XtPointer) i1); } - (void) strcpy(buffer, (GETMESSAGE(NL_SETN_ViewMenu,9, "Default"))); + snprintf(buffer, sizeof(buffer), "%s", (GETMESSAGE(NL_SETN_ViewMenu,9, "Default"))); fontSizeToggles[i1] = _DtTermViewCreateToggleButton(submenu, buffer, 0, NULL, NULL, defaultFontCallback, NULL); fontSizeTogglesDefault = i1; diff --git a/cde/lib/DtTerm/util/lineToData.c b/cde/lib/DtTerm/util/lineToData.c index c1fae2d0..0240f2c3 100644 --- a/cde/lib/DtTerm/util/lineToData.c +++ b/cde/lib/DtTerm/util/lineToData.c @@ -131,7 +131,7 @@ char **argv; } /* back up buffer... */ - (void) strncpy(orig, buffer, BUFSIZ); + (void) strncpy(orig, buffer, BUFSIZ - 1); bufPtr = buffer;