From: Peter Howkins Date: Mon, 30 Apr 2018 03:11:44 +0000 (+0100) Subject: dthelp: Further coverity fixes X-Git-Tag: 2.2.4a~45 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=48b97a4c417380c37f74d91a04af4b3ba0007eac;p=oweals%2Fcde.git dthelp: Further coverity fixes --- diff --git a/cde/programs/dthelp/dthelpgen/helpgen.c b/cde/programs/dthelp/dthelpgen/helpgen.c index 08abc7c8..8ac04cf4 100644 --- a/cde/programs/dthelp/dthelpgen/helpgen.c +++ b/cde/programs/dthelp/dthelpgen/helpgen.c @@ -305,7 +305,6 @@ CreateVolumeLink ( char *title = NULL; char *charSet = (char *) DefCharSet; char *abstract = NULL; - char *filename = NULL; char *pathName = NULL; VolumeHandle volume = NULL; @@ -359,8 +358,6 @@ CreateVolumeLink ( if (title) free ((void *) title); - if (filename) - free ((void *) filename); return result; } diff --git a/cde/programs/dthelp/dthelpprint/PrintManStrFile.c b/cde/programs/dthelp/dthelpprint/PrintManStrFile.c index 94229e87..9a3d1195 100644 --- a/cde/programs/dthelp/dthelpprint/PrintManStrFile.c +++ b/cde/programs/dthelp/dthelpprint/PrintManStrFile.c @@ -218,10 +218,11 @@ int _DtHPrPrintManPage( } /* Alloc max shell command line len */ - printCommand = malloc(MAX_COMMAND_LENGTH*sizeof(char)); + printCommand = malloc(MAX_COMMAND_LENGTH); if (printCommand == NULL) { fprintf(stderr, _DTGETMESSAGE(PMSET,5, + "%s: Error: memory allocation failed\n"), options->programName ); @@ -231,7 +232,7 @@ int _DtHPrPrintManPage( /** generate the command **/ snprintf(cmdFormat, sizeof(cmdFormat), "%s %s", /* man */ options->manCommand, options->manArgs); - snprintf(printCommand, sizeof(MAX_COMMAND_LENGTH*sizeof(char)), cmdFormat, + snprintf(printCommand, MAX_COMMAND_LENGTH, cmdFormat, options->manPage); /* man */ retval = _DtHPrGenFileOrPrint(options,options->manPage,printCommand); diff --git a/cde/programs/dthelp/dthelpprint/PrintTopics.c b/cde/programs/dthelp/dthelpprint/PrintTopics.c index 3fe4917c..c5a60995 100644 --- a/cde/programs/dthelp/dthelpprint/PrintTopics.c +++ b/cde/programs/dthelp/dthelpprint/PrintTopics.c @@ -2273,13 +2273,11 @@ int ProcessTopics( /* if processing subtopics, start processing at the top */ if ( processSubTopics ) { - char * name = NULL; int offset; /* get the top topic of the volume */ ret = _DtHelpCeGetTopTopicId(state->volHandle, &state->currentLocId); if (ret != True) state->currentLocId = strdup("_HOMETOPIC"); - if(name) free(name); } else { /* otherwise, process only where needed */ @@ -2413,7 +2411,7 @@ int DoHelpTopicsProcessing( char * buf; char * start; char * next; - char * pgbrkFile; + char * pgbrkFile = NULL; char * partFiles[NUMPARTS]; Boolean validFile = False; @@ -2514,7 +2512,10 @@ cleanup: unlink(partFiles[i]); free(partFiles[i]); } - unlink(pgbrkFile); + + if(pgbrkFile) { + unlink(pgbrkFile); + } /* NOTE: should free Toc here if interested in no leaks */ diff --git a/cde/programs/dthelp/dthelpview/Util.c b/cde/programs/dthelp/dthelpview/Util.c index 36dc8561..b5608d97 100644 --- a/cde/programs/dthelp/dthelpview/Util.c +++ b/cde/programs/dthelp/dthelpview/Util.c @@ -166,13 +166,16 @@ void CloseHelpCB ( pTemp = pCacheListHead; /* Search our Cache List for the closed help dialog */ - while ((pTemp->helpDialog != helpDialog) && (pTemp != NULL)) + while ((pTemp != NULL) && (pTemp->helpDialog != helpDialog)) pTemp = pTemp->pNext; - if (pTemp == NULL) + if (pTemp == NULL) { /* ERROR */ printf("We did not find our help dialog widget in the cache list??? /n"); + /* TODO what error handling here? */ + return; + } /* Un Map and Clean up the help widget */ XtUnmanageChild(helpDialog); diff --git a/cde/programs/dthelp/parser/canon1/eltdef/eltdef.c b/cde/programs/dthelp/parser/canon1/eltdef/eltdef.c index 16057461..45540d03 100644 --- a/cde/programs/dthelp/parser/canon1/eltdef/eltdef.c +++ b/cde/programs/dthelp/parser/canon1/eltdef/eltdef.c @@ -75,7 +75,7 @@ int main(argc, argv) fprintf(stderr, "**** Specify interface file ****\n") ; exit(TRUE) ; } - strncpy(iffile, argv[1], IFLEN) ; + snprintf(iffile, sizeof(iffile), "%s", argv[1]) ; initialize() ; while (TRUE) { m_token = scan() ; diff --git a/cde/programs/dthelp/parser/canon1/helptag/help.c b/cde/programs/dthelp/parser/canon1/helptag/help.c index 351cd22a..30837d33 100644 --- a/cde/programs/dthelp/parser/canon1/helptag/help.c +++ b/cde/programs/dthelp/parser/canon1/helptag/help.c @@ -126,7 +126,7 @@ if ( *(m_argv[0]) == '/' ) else { /* not fully specified, check each component of path for ourself */ - strcpy(patbuf, getenv("PATH")); + snprintf(patbuf, sizeof(patbuf), "%s", getenv("PATH")); path = patbuf; cp = path; @@ -538,8 +538,10 @@ M_WCHAR *parent, *gentity, *gposition, *ghyperlink, *glinktype, *gdescription; { unsigned char etype, wheredef; char *mb_content, *ssi, id[32]; -static M_WCHAR empty = M_EOS; +static M_WCHAR empty[1]; char *leftright; +empty[0] = M_EOS; + /* handle graphic specific code */ /* initialize some stuff first: @@ -627,7 +629,7 @@ if (gentity) gentity); } } - if (!f_content) f_content = ∅ + if (!f_content) f_content = empty; mb_content = MakeMByteString(f_content); sprintf(id, "%s%d", sdlReservedName, NextId()); @@ -718,7 +720,7 @@ int count, metaCount; char *item_id; char label_id[SDLNAMESIZ+10]; int listtype; -char *type; +char *type = NULL; char *loose; char *first; LOGICAL isBullet, isLoose, isFirst; @@ -824,9 +826,10 @@ if (listtype == ORDER) switch (lastlist->lastlist->order) { case UROMAN: - strcpy(orderString, ROMAN100[count / 100]); - strcat(orderString, ROMAN10[(count / 10) % 10]); - strcat(orderString, ROMAN0[count % 10]); + snprintf(orderString, sizeof(orderString), "%s%s%s", + ROMAN100[count / 100], + ROMAN10[(count / 10) % 10], + ROMAN0[count % 10]); type = romanString; break; case UALPHA: @@ -848,9 +851,10 @@ if (listtype == ORDER) type = arabicString; break; case LROMAN: - strcpy(orderString, roman100[count / 100]); - strcat(orderString, roman10[(count / 10) % 10]); - strcat(orderString, roman0[count % 10]); + snprintf(orderString, sizeof(orderString), "%s%s%s", + roman100[count / 100], + roman10[(count / 10) % 10], + roman0[count % 10]); type = romanString; break; case LALPHA: @@ -868,7 +872,7 @@ if (listtype == ORDER) "%s%s-%s\">\n

%s%c", first, loose, - type, + type ? type : "", orderString, lastlist->lastlist->punct == DOTPUNCT ? '.' : ')' ); if (id) @@ -1508,17 +1512,19 @@ _DtXlateDb myDb = NULL; char myPlatform[_DtPLATFORM_MAX_LEN+1]; char myLocale[256]; /* arbitrarily large */ char *locale; -char *lang; -char *charset; +char *lang = NULL; +char *charset = NULL; int execVer; int compVer; int isStd; -strcpy(myLocale, pLang); if (*pCharset) { - strcat(myLocale, "."); - strcat(myLocale, pCharset); + snprintf(myLocale, sizeof(myLocale), "%s.%s", pLang, pCharset); + } +else + { + snprintf(myLocale, sizeof(myLocale), "%s", pLang); } if ((_DtLcxOpenAllDbs(&myDb) != 0) || @@ -1601,7 +1607,6 @@ else if (*lang) { strcpy(pLang, lang); - mb_free(&lang); } else strcpy(pLang, cString); @@ -1609,13 +1614,16 @@ else if (*charset) { strcpy(pCharset, charset); - mb_free(&charset); - free(charset); } else strcpy(pCharset, isoString); } + mb_free(&lang); + mb_free(&charset); + free(charset); + + _DtLcxCloseDb(&myDb); } @@ -1773,9 +1781,9 @@ if (!charset) if (dotPtr) *dotPtr = 0; -strcpy(stdLang, locale); +snprintf(stdLang, sizeof(stdLang), "%s", locale); if (charset) - strcpy(stdCharset, charset); + snprintf(stdCharset, sizeof(stdCharset), "%s", charset); SetStdLocale(stdLang, stdCharset); if (*stdCharset) @@ -2049,10 +2057,12 @@ if (file) sprintf(snb_id, "%s%d", sdlReservedName, NextId()); { -static M_WCHAR empty = M_EOS; +static M_WCHAR empty[1]; char *mb_content; +empty[0] = M_EOS; + -if (!f_content) f_content = ∅ +if (!f_content) f_content = empty; mb_content = MakeMByteString(f_content); AddToSNB(snb_id, mb_content); @@ -2763,8 +2773,8 @@ if (*icon) fputs("CLASS=\"ICON\" SSI=\"NCW-ICON\">", outfile); fputs("\n\n", outfile); AddToSNB(id, icon); - m_free(icon, "icon name"); } +m_free(icon, "icon name"); } @@ -2838,8 +2848,7 @@ while (thispath) else try = mb_realloc(try, tryleng); } - strcpy(try, thispath->directory); - strcpy(try + pathleng, mb_inputname); + sprintf(try, "%s%s", thispath->directory, mb_inputname); tossfile = open(try, O_RDONLY); if (tossfile >= 0) break; thispath = thispath->next; diff --git a/cde/programs/dthelp/parser/canon1/helptag/help.if b/cde/programs/dthelp/parser/canon1/helptag/help.if index d8ec9ce0..e5519812 100644 --- a/cde/programs/dthelp/parser/canon1/helptag/help.if +++ b/cde/programs/dthelp/parser/canon1/helptag/help.if @@ -516,15 +516,15 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su if (termp - term > 1 && *(termp-1) == ' ') { *(termp-1) = M_EOS; } - if (!(lastTermId = (int) m_lookfortrie(term, >ree))) + if (!(lastTermId = (int)(intptr_t) m_lookfortrie(term, >ree))) { lastTermId = NextId(); - m_ntrtrie(term, >ree, (void *) -lastTermId); + m_ntrtrie(term, >ree, (void *)(intptr_t) -lastTermId); } else if (lastTermId > 0) { - if (!m_resettrie(>ree, term, (void *) -lastTermId)) + if (!m_resettrie(>ree, term, (void *)(intptr_t) -lastTermId)) { m_error("Internal error. Can't reset glossary trie") ; m_exit(TRUE) ; @@ -685,7 +685,7 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su m_error("Program error: exceeded chapstring") ; m_exit(TRUE) ; } - sprintf(chapstring, sizeof(chapstring), "%s", string) ; + snprintf(chapstring, sizeof(chapstring), "%s", string) ; fputs("\nGlossary\n", stderr) ; glossary = TRUE ; fprintf(outfile, "%s\n", string); @@ -778,9 +778,10 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su { char *mb_content, snb_id[32]; char buffer[BIGBUF]; - static M_WCHAR empty = M_EOS; + static M_WCHAR empty[1]; + empty[0] = M_EOS; - if (!f_content) f_content = ∅ + if (!f_content) f_content = empty; mb_content = MakeMByteString(f_content); sprintf(snb_id, "%s%d", sdlReservedName, NextId()); diff --git a/cde/programs/dthelp/parser/canon1/helptag/out.c b/cde/programs/dthelp/parser/canon1/helptag/out.c index 9d0ab2b6..01c6e298 100644 --- a/cde/programs/dthelp/parser/canon1/helptag/out.c +++ b/cde/programs/dthelp/parser/canon1/helptag/out.c @@ -198,7 +198,7 @@ if (bufflen == 1) exLineNum++; if (special[index]) { - strcpy(exbuff, special[index]); + snprintf(exbuff, sizeof(exbuff), "%s", special[index]); bufflen = strlen(exbuff); } } @@ -230,7 +230,7 @@ if (bufflen == 1) index = (unsigned char) imbuff[0]; if (special[index]) { - strcpy(imbuff, special[index]); + snprintf(imbuff, sizeof(imbuff), "%s", special[index]); bufflen = strlen(imbuff); } mb_strcode(imbuff, outfile); diff --git a/cde/programs/dthelp/parser/canon1/util/entout.c b/cde/programs/dthelp/parser/canon1/util/entout.c index aff174aa..f731e767 100644 --- a/cde/programs/dthelp/parser/canon1/util/entout.c +++ b/cde/programs/dthelp/parser/canon1/util/entout.c @@ -72,8 +72,7 @@ void entout(fname) int nameindex ; LOGICAL start ; - strncpy(efilename, fname, ENTFILENAME) ; - strncpy(&efilename[strlen(efilename)], ".h", 2) ; + snprintf(efilename, sizeof(efilename), "%s.h", fname) ; m_openchk(&entfile, efilename, "w") ; fprintf(entfile, "#include \"entdef.h\"\n") ; diff --git a/cde/programs/dthelp/parser/pass1/helptag/custom.c b/cde/programs/dthelp/parser/pass1/helptag/custom.c index 478feabf..1813100b 100644 --- a/cde/programs/dthelp/parser/pass1/helptag/custom.c +++ b/cde/programs/dthelp/parser/pass1/helptag/custom.c @@ -210,7 +210,11 @@ SEARCH *searchp; char *mb_entcontent; mb_entcontent = MakeMByteString(entcontent); -if (!*mb_entcontent) return NULL; /* null file name, don't open a directory */ +if (!*mb_entcontent) /* null file name, don't open a directory */ + { + m_free(mb_entcontent, "multi-byte string"); + return NULL; + } open = fopen(mb_entcontent, "r"); if (open) @@ -301,7 +305,9 @@ void m_signmsg(p) if (q = strstr(p, VERSION)) { pCopy = strdup(p); q = strstr(pCopy, VERSION); - *q = M_EOS; + if(q) { + *q = M_EOS; + } m_errline(pCopy); free(pCopy); return; diff --git a/cde/programs/dthelp/parser/pass1/helptag/help.if b/cde/programs/dthelp/parser/pass1/helptag/help.if index a18fe110..6b8b268a 100644 --- a/cde/programs/dthelp/parser/pass1/helptag/help.if +++ b/cde/programs/dthelp/parser/pass1/helptag/help.if @@ -870,9 +870,10 @@ static char ident6[]="@(#) (c) Copyright 1993, 1994 Unix System Labs, Inc., a su { char *mb_content, snb_id[32]; char buffer[BIGBUF]; - static M_WCHAR empty = M_EOS; + static M_WCHAR empty[1]; + empty[0] = M_EOS; - if (!f_content) f_content = ∅ + if (!f_content) f_content = empty; mb_content = MakeMByteString(f_content); sprintf(snb_id, "%s%d", sdlReservedName, NextId()); diff --git a/cde/programs/dthelp/parser/pass1/helptag/xref.c b/cde/programs/dthelp/parser/pass1/helptag/xref.c index b92cb07c..be0aac82 100644 --- a/cde/programs/dthelp/parser/pass1/helptag/xref.c +++ b/cde/programs/dthelp/parser/pass1/helptag/xref.c @@ -153,6 +153,9 @@ FILE *tex; strcpy(helpext, ".xrh"); tex = fopen(helpbase, "w"); +if (! tex) { + return; +} fprintf(tex, "\\gobble\001%s\002%%\n", m_signon); fputs("% Generated Cross-Reference Macros (for a particular document)\n", tex); if (! xtree.data) { diff --git a/cde/programs/dthelp/parser/pass1/util/malloc.c b/cde/programs/dthelp/parser/pass1/util/malloc.c index 19312af8..3ce3594d 100644 --- a/cde/programs/dthelp/parser/pass1/util/malloc.c +++ b/cde/programs/dthelp/parser/pass1/util/malloc.c @@ -93,7 +93,6 @@ void m_free(block, msg) #if defined(MSDOS) if (m_heapchk) m_heapdump() ; #endif - free(block) ; if (m_malftrace) { #if defined(hpux) || defined(_AIX) || defined(sun) || defined(USL) || defined(__uxp__) snprintf(buffer, 32, "%5x:%5x", @@ -107,6 +106,7 @@ void m_free(block, msg) m_trace(msg) ; m_trace("\n") ; } + free(block) ; #if defined(MSDOS) if (m_heapchk) m_heapdump() ; #endif diff --git a/cde/programs/dthelp/parser/pass2/build/out.c b/cde/programs/dthelp/parser/pass2/build/out.c index 469659da..c15696b3 100644 --- a/cde/programs/dthelp/parser/pass2/build/out.c +++ b/cde/programs/dthelp/parser/pass2/build/out.c @@ -483,7 +483,7 @@ char *partype(n) void srefout(M_NOPAR) { LOGICAL first = TRUE ; - int *mapbysref ; + int *mapbysref = NULL; SREFSTRUCT *srefp ; SREFDATA *data ; int count = 0 ; diff --git a/cde/programs/dthelp/parser/pass2/htag2/sdl.c b/cde/programs/dthelp/parser/pass2/htag2/sdl.c index 84e5d61f..b302f040 100644 --- a/cde/programs/dthelp/parser/pass2/htag2/sdl.c +++ b/cde/programs/dthelp/parser/pass2/htag2/sdl.c @@ -1563,7 +1563,7 @@ static void MarkUsedStyle(level, class, ssi) #endif { ElementPtr pThis; -M_WCHAR *rlevel, *rclass, *rssi; +M_WCHAR *rlevel = NULL, *rclass = NULL, *rssi = NULL; LOGICAL *pBeenUsed; pThis = pTossChain;