diff --git a/cde/lib/DtHelp/Access.c b/cde/lib/DtHelp/Access.c index d0b79d6f5..9e040c3c8 100644 --- a/cde/lib/DtHelp/Access.c +++ b/cde/lib/DtHelp/Access.c @@ -588,9 +588,10 @@ FileOpenRtnFd ( if (*ret_fd == -1) { /* - * get a temporary name + * get a temporary name using mkstemp for security */ - (void) tmpnam (tmpName); + strcpy(tmpName, "/tmp/dthelp_XXXXXX"); + { int _tf = mkstemp(tmpName); if (_tf >= 0) close(_tf); } /* * malloc memory for the dot Z file name. @@ -1087,9 +1088,10 @@ _DtHelpCeGetUncompressedFileName ( if (access (name, F_OK) == -1) { /* - * get a temporary name + * get a temporary name using mkstemp for security */ - (void) tmpnam (tmpName); + strcpy(tmpName, "/tmp/dthelp_XXXXXX"); + { int _tf = mkstemp(tmpName); if (_tf >= 0) close(_tf); } /* * malloc memory for the dot Z file name. diff --git a/cde/lib/DtSvc/DtUtil1/DtsMM.c b/cde/lib/DtSvc/DtUtil1/DtsMM.c index 8c5c2fcf9..6b7facb02 100644 --- a/cde/lib/DtSvc/DtUtil1/DtsMM.c +++ b/cde/lib/DtSvc/DtUtil1/DtsMM.c @@ -569,14 +569,15 @@ _DtDtsMMCacheName(int override) { /* tempnam(3) is affected by the TMPDIR environment variable. */ /* This creates problems for rename() if "tmpfile" and "cacheFile" */ - /* are on different file systems. Use tmpnam(3) to create the */ + /* are on different file systems. Use mkstemp(3) to create the */ /* unique file name instead. */ - char tmpnam_buf[L_tmpnam + 1]; + char tmpnam_buf[32]; results = (char *)malloc(strlen(_DTDTSMMTEMPDIR) + strlen(_DTDTSMMTEMPFILE) + - L_tmpnam + 3); - tmpnam(tmpnam_buf); + 32); + strcpy(tmpnam_buf, "/tmp/dtdts_XXXXXX"); + { int _tf = mkstemp(tmpnam_buf); if (_tf >= 0) close(_tf); } sprintf(results, "%s/%s%s", _DTDTSMMTEMPDIR, _DTDTSMMTEMPFILE, basename(tmpnam_buf)); } diff --git a/cde/lib/DtWidget/Editor.c b/cde/lib/DtWidget/Editor.c index 9d6c750b4..1528764fa 100644 --- a/cde/lib/DtWidget/Editor.c +++ b/cde/lib/DtWidget/Editor.c @@ -5181,6 +5181,7 @@ typedef struct { #define WORDPREV(d,at) (((at == d->wordbase) ? d->wordlimit : at) - 1) /* function */ #include +#include extern int _nl_space_alt; @@ -6873,7 +6874,7 @@ DoAdjust( XmTextPosition start, XmTextPosition end) { - char tempName1[L_tmpnam], tempName2[L_tmpnam]; + char tempName1[32], tempName2[32]; DtEditorErrorCode returnVal; AdjRec adjRec; @@ -6961,8 +6962,9 @@ DoAdjust( /* * Create the two temp files */ - (void)tmpnam(tempName1); - (void)tmpnam(tempName2); + strcpy(tempName1, "/tmp/dtedit1_XXXXXX"); + strcpy(tempName2, "/tmp/dtedit2_XXXXXX"); + { int _tf1 = mkstemp(tempName1), _tf2 = mkstemp(tempName2); if (_tf1 >= 0) close(_tf1); if (_tf2 >= 0) close(_tf2); } if ((adjRec.infp = fopen(tempName1, "w")) != (FILE *)NULL) { /* diff --git a/cde/lib/DtWidget/SearchCalls.c b/cde/lib/DtWidget/SearchCalls.c index 7be84a921..26eddb88e 100644 --- a/cde/lib/DtWidget/SearchCalls.c +++ b/cde/lib/DtWidget/SearchCalls.c @@ -60,6 +60,7 @@ #define X_INCLUDE_STRING_H #define XOS_USE_XT_LOCKING #include +#include extern XtPointer _XmStringUngenerate(XmString string, @@ -96,7 +97,7 @@ DtEditorInvokeSpellDialog( Widget widget) { DtEditorWidget pPriv = (DtEditorWidget) widget; - char fileName[L_tmpnam], com[L_tmpnam + 7], *string, newline[1]; + char fileName[32], com[32 + 7], *string, newline[1]; char *line; FILE *fp; /* pipe to read words from */ int len = 0; /* length of line read in */ @@ -119,7 +120,8 @@ DtEditorInvokeSpellDialog( /* * Write out to a tmp file, getting the name back */ - (void)tmpnam(fileName); + strcpy(fileName, "/tmp/dtsrch_XXXXXX"); + { int _tf = mkstemp(fileName); if (_tf >= 0) close(_tf); } if((fp = fopen(fileName, "w")) != (FILE *)NULL) { /* diff --git a/cde/programs/dtcreate/main.c b/cde/programs/dtcreate/main.c index 3e729b94e..67d1528a9 100644 --- a/cde/programs/dtcreate/main.c +++ b/cde/programs/dtcreate/main.c @@ -226,6 +226,7 @@ const char *af_tiny_icon_default = "/usr/dt/appconfig/icons/C/Dtdata.t"; *---------------------------------------------------*/ #ifndef DESIGN_TIME #include "UxXt.h" +#include #endif /* DESIGN_TIME */ XtAppContext UxAppContext; @@ -873,7 +874,8 @@ Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p ) if (pIconData->pmDirtyBit) { tmpIconFile = pIconData->pmFileName; } else { - tmpnam(pIconData->pmFileName); + strcpy(pIconData->pmFileName, "/tmp/dtcreate_pm_XXXXXX"); + { int _tf = mkstemp(pIconData->pmFileName); if (_tf >= 0) close(_tf); } bIsNewFile = True; tmpIconFile = pIconData->pmFileName; } @@ -881,7 +883,8 @@ Tt_callback_action IconEdit_tt_handler( Tt_message m, Tt_pattern p ) if (pIconData->bmDirtyBit) { tmpIconFile = pIconData->bmFileName; } else { - tmpnam(pIconData->bmFileName); + strcpy(pIconData->bmFileName, "/tmp/dtcreate_bm_XXXXXX"); + { int _tf = mkstemp(pIconData->bmFileName); if (_tf >= 0) close(_tf); } bIsNewFile = True; tmpIconFile = pIconData->bmFileName; } diff --git a/cde/programs/dticon/main.c b/cde/programs/dticon/main.c index 9dd4c5f4f..45aae8004 100644 --- a/cde/programs/dticon/main.c +++ b/cde/programs/dticon/main.c @@ -58,6 +58,7 @@ #ifdef __TOOLTALK #include +#include int ttMark; int tt_tmpfile_fd = -1; static int undeclared = 0; @@ -521,7 +522,8 @@ if (tt_message_status(msg) == TT_WRN_START_MESSAGE) tt_message_reply(msg); } else { - (void) tmpnam(start_file); + strcpy(start_file, "/tmp/dticon_XXXXXX"); + { int _tf = mkstemp(start_file); if (_tf >= 0) close(_tf); } if( (buf) && (!strncmp((char *)buf, "/* XPM */", 9)) ) { /* Format XPM */ diff --git a/cde/programs/dtlogin/policy.c b/cde/programs/dtlogin/policy.c index 1b61b0d75..3db59f298 100644 --- a/cde/programs/dtlogin/policy.c +++ b/cde/programs/dtlogin/policy.c @@ -246,7 +246,7 @@ WillingMsg( void ) static char retbuf[LINEBUFSIZE]; char tmpbuf[LINEBUFSIZE * 8]; char *cp; - char tmpfilename[L_tmpnam + 1]; + char tmpfilename[32]; FILE *f; @@ -260,7 +260,9 @@ WillingMsg( void ) strcat(tmpbuf,"awk '{printf(\"%s %-.5s load: %.3s, %.3s, %.3s\",$(NF-6),$(NF-5),$(NF-2),$(NF-1),$NF)}'"); strcat(tmpbuf," > "); - if ( tmpnam(tmpfilename) != (char *)NULL ) { + strcpy(tmpfilename, "/tmp/dtlogin_XXXXXX"); + { int _tf = mkstemp(tmpfilename); if (_tf >= 0) close(_tf); } + if ( tmpfilename[0] != '\0' ) { strcat(tmpbuf,tmpfilename); diff --git a/cde/programs/dtpad/fileIo.c b/cde/programs/dtpad/fileIo.c index 7f265c221..c8cf8fd6c 100644 --- a/cde/programs/dtpad/fileIo.c +++ b/cde/programs/dtpad/fileIo.c @@ -58,6 +58,7 @@ #include #include #include
+#include /************************************************************************ @@ -255,10 +256,11 @@ LoadFile( char * GetTempFile(void) { - char *tempname = (char *)XtMalloc(L_tmpnam); /* Temporary file name. */ + char *tempname = (char *)XtMalloc(32); /* Temporary file name. */ FILE *tfp; - (void)tmpnam(tempname); + strcpy(tempname, "/tmp/dtpad_XXXXXX"); + { int _tf = mkstemp(tempname); if (_tf >= 0) close(_tf); } if ((tfp = fopen(tempname, "w")) == NULL) { pid_t pid; diff --git a/cde/programs/dtpdm/PdmXp.c b/cde/programs/dtpdm/PdmXp.c index 05b2b4ef9..bcff224d1 100644 --- a/cde/programs/dtpdm/PdmXp.c +++ b/cde/programs/dtpdm/PdmXp.c @@ -38,6 +38,7 @@ #include "PdmXp.h" #include +#include typedef enum { PDMXP_JOB, PDMXP_DOC, PDMXP_PRINTER, PDMXP_SERVER, @@ -488,9 +489,11 @@ void PdmXpUpdateAttributes(PdmXp* me) { #if 0 && defined(PRINTING_SUPPORTED) - char fname[L_tmpnam]; + char fname[32]; - if(tmpnam(fname)) + strcpy(fname, "/tmp/dtpdm_XXXXXX"); + { int _tf = mkstemp(fname); if (_tf >= 0) close(_tf); } + if(fname[0] != '\0') { int i; XrmDatabase pool; diff --git a/cde/programs/dtpdmd/manager.c b/cde/programs/dtpdmd/manager.c index 98df74459..b30884eeb 100644 --- a/cde/programs/dtpdmd/manager.c +++ b/cde/programs/dtpdmd/manager.c @@ -363,7 +363,8 @@ void mgr_launch_pdm( XpPdmServiceRec *rec ) * Create new .Xauthority file. */ original_umask = umask (0077); /* disallow non-owner access */ - tmpnam( rec->auth_filename ); + strcpy(rec->auth_filename, "/tmp/dtpdmd_XXXXXX"); + { int _tf = mkstemp(rec->auth_filename); if (_tf >= 0) close(_tf); } rec->auth_file = fopen( rec->auth_filename, "w" ); if (rec->auth_file) { diff --git a/cde/programs/dtspcd/main.c b/cde/programs/dtspcd/main.c index 7b02b79bc..1e8c43997 100644 --- a/cde/programs/dtspcd/main.c +++ b/cde/programs/dtspcd/main.c @@ -506,7 +506,7 @@ int Client_Register(protocol_request_ptr prot) int free_netfile = 0; char *spc_prefix = "/.SPC_"; char *spc_suffix; - char tmpnam_buf[L_tmpnam + 1]; + char tmpnam_buf[32]; size_t buffsize; print_protocol_request((XeString)"--> REGISTER", prot); @@ -560,7 +560,8 @@ int Client_Register(protocol_request_ptr prot) * tmppath. The protocol will fail when this occurs. The fix is * to construct the tmpfile name. */ - tmpnam(tmpnam_buf); + strcpy(tmpnam_buf, "/tmp/dtspcd_XXXXXX"); + { int _tf = mkstemp(tmpnam_buf); if (_tf >= 0) close(_tf); } spc_suffix = basename(tmpnam_buf); /* Don't free result - not alloc'd! */ /* Allocate space for tmppath, spc_prefix, and spc_suffix. */ diff --git a/cde/programs/dtwm/WmResParse.c b/cde/programs/dtwm/WmResParse.c index 86f8f9a55..ba7202858 100644 --- a/cde/programs/dtwm/WmResParse.c +++ b/cde/programs/dtwm/WmResParse.c @@ -96,6 +96,7 @@ #include "WmFunction.h" #include "WmImage.h" #include "WmXSMP.h" +#include # include # ifdef X_NOT_STDC_ENV @@ -5971,7 +5972,7 @@ Boolean ParseWmFuncActionArg (unsigned char **linePP, static void PreprocessConfigFile (void) { -#define CPP_NAME_SIZE ((L_tmpnam)+1) +#define CPP_NAME_SIZE 32 char pchCmd[MAXWMPATH+1]; if (wmGD.cppCommand && *wmGD.cppCommand) @@ -5982,7 +5983,8 @@ PreprocessConfigFile (void) pConfigStackTop->cppName = XtMalloc (CPP_NAME_SIZE * sizeof(char)); if (pConfigStackTop->cppName) { - (void) tmpnam (pConfigStackTop->cppName); + strcpy(pConfigStackTop->cppName, "/tmp/dtwm_XXXXXX"); + { int _tf = mkstemp(pConfigStackTop->cppName); if (_tf >= 0) close(_tf); } /* * Build up the command line.