1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Merge branch 'coverity_dtsession'

Fix up a bunch (55) issues in dtsession identified by Coverity's
static analysis.
This commit is contained in:
Jon Trulson 2014-12-27 20:25:26 -07:00
commit f6d6aafc93
9 changed files with 147 additions and 80 deletions

View file

@ -786,7 +786,7 @@ ProcessClientMessage(
_DtAddToResource(smGD.display, newRes); _DtAddToResource(smGD.display, newRes);
} }
if (NULL != newRes) free(newRes); free(newRes);
} }
} }
else if (cEvent->message_type == XaDtSmSaverInfo) else if (cEvent->message_type == XaDtSmSaverInfo)

View file

@ -498,7 +498,8 @@ OpenOutputClientDB(char *fileName,
/* Open fileName for writing. */ /* Open fileName for writing. */
if ((outputDB->xrmDBFile = fopen(fileName, "w")) == (FILE *)NULL) if ((outputDB->xrmDBFile = fopen(fileName, "w")) == (FILE *)NULL)
{ {
rename(outputDB->tmpDBFileName, fileName); int rv;
rv = rename(outputDB->tmpDBFileName, fileName);
XtFree(outputDB->xrmDBFileName); XtFree(outputDB->xrmDBFileName);
XtFree(outputDB->tmpDBFileName); XtFree(outputDB->tmpDBFileName);
XtFree((char *)outputDB); XtFree((char *)outputDB);
@ -705,9 +706,10 @@ CloseClientDB(ClientDB clientDBPtr, Boolean writeDB)
} }
else else
{ {
int rv;
/* Close file and remove it; restore original DB. */ /* Close file and remove it; restore original DB. */
fclose(clientDB->xrmDBFile); fclose(clientDB->xrmDBFile);
rename(clientDB->tmpDBFileName, clientDB->xrmDBFileName); rv = rename(clientDB->tmpDBFileName, clientDB->xrmDBFileName);
} }
XtFree(clientDB->xrmDBFileName); XtFree(clientDB->xrmDBFileName);

View file

@ -476,7 +476,7 @@ InitSMGlobals( void )
/* /*
* Pull screen saver resources from Dtsession*<name>. * Pull screen saver resources from Dtsession*<name>.
*/ */
smGD.SmNextension = smGD.SmNextension = smGD.extensionSpec = ""; smGD.SmNextension = smGD.SmCextension = smGD.extensionSpec = "";
} }
XtGetSubresources(smGD.topLevelWid, (XtPointer) &smSaverRes, XtGetSubresources(smGD.topLevelWid, (XtPointer) &smSaverRes,
@ -684,7 +684,7 @@ SetRestorePath(
*/ */
if (getenv("DISPLAY") == 0) if (getenv("DISPLAY") == 0)
{ {
sprintf(tmpDisplayName, "DISPLAY=%s", displayName); snprintf(tmpDisplayName, MAXPATHLEN, "DISPLAY=%s", displayName);
putenv(tmpDisplayName); putenv(tmpDisplayName);
} }
} }
@ -703,7 +703,7 @@ SetRestorePath(
pch = strdup ((char *) GETMESSAGE (40, 15, pch = strdup ((char *) GETMESSAGE (40, 15,
" No session name was provided for the -session command line option.")); " No session name was provided for the -session command line option."));
if (!pch) if (pch)
{ {
DtMsgLogMessage (argv[0], DtMsgLogWarning, pch); DtMsgLogMessage (argv[0], DtMsgLogWarning, pch);
free (pch); free (pch);
@ -1109,22 +1109,31 @@ SetSavePath(
if(status == 0) if(status == 0)
{ {
char * tmpName; char * tmpName;
char * tmpDir; int len, tfd;
strcpy (savedOldDir, smGD.etcPath); strcpy(savedOldDir, smGD.etcPath);
tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2); len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
sprintf (tmpName, "%s.", smGD.restoreSession); + strlen("XXXXXX") + 3;
if (strlen (tmpName) > 5) { tmpName = (char *) XtCalloc(1, len);
tmpName[4] = '.';
tmpName[5] = '\000';
}
tmpDir = (char *) tempnam (smGD.savePath, tmpName);
MoveDirectory (smGD.etcPath, tmpDir, False);
strcpy (savedTmpDir, tmpDir); sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath,
free (tmpDir); smGD.restoreSession);
XtFree ((char *) tmpName);
if ((tfd = mkstemp(tmpName)) == -1)
{
PrintErrnoError(DtError, smNLS.cantCreateDirsString);
}
else
{
close(tfd);
unlink(tmpName);
MoveDirectory(smGD.etcPath, tmpName, False);
strncpy(savedTmpDir, tmpName, len - 1);
}
XtFree((char *) tmpName);
} }
MoveDirectory(smGD.clientPath, smGD.etcPath, False); MoveDirectory(smGD.clientPath, smGD.etcPath, False);
} }
@ -1165,25 +1174,35 @@ SetSavePath(
* save is complete. * save is complete.
*/ */
char * tmpName; char * tmpName;
char * tmpDir;
sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION); sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
status = stat(smGD.etcPath, &buf); status = stat(smGD.etcPath, &buf);
if(status == 0) if(status == 0)
{ {
tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2); int len, tfd;
sprintf (tmpName, "%s.", smGD.restoreSession);
strcpy (savedOldDir, smGD.etcPath);
if (strlen (tmpName) > 5) {
tmpName[4] = '.';
tmpName[5] = '\000';
}
tmpDir = (char *) tempnam (smGD.savePath, tmpName);
MoveDirectory (smGD.etcPath, tmpDir, False);
strcpy (savedTmpDir, tmpDir); len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
free (tmpDir); + strlen("XXXXXX") + 3;
XtFree ((char *) tmpName); tmpName = (char *) XtCalloc(1, len);
sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath,
smGD.restoreSession);
strcpy (savedOldDir, smGD.etcPath);
if ((tfd = mkstemp(tmpName)) == -1)
{
PrintErrnoError(DtError, smNLS.cantCreateDirsString);
}
else
{
close(tfd);
unlink(tmpName);
MoveDirectory (smGD.etcPath, tmpName, False);
strcpy (savedTmpDir, tmpName);
}
XtFree((char *) tmpName);
} }
MoveDirectory(smGD.clientPath, smGD.etcPath, False); MoveDirectory(smGD.clientPath, smGD.etcPath, False);
@ -1194,13 +1213,21 @@ SetSavePath(
status = mkdir(smGD.clientPath, 0000); status = mkdir(smGD.clientPath, 0000);
if(status == -1) if(status == -1)
{ {
PrintErrnoError(DtError, smNLS.cantCreateDirsString);
smGD.clientPath[0] = 0;
smGD.settingPath[0] = 0;
smGD.resourcePath[0] = 0;
return(-1);
}
status = chmod(smGD.clientPath, 0755);
if(status == -1)
{
PrintErrnoError(DtError, smNLS.cantCreateDirsString); PrintErrnoError(DtError, smNLS.cantCreateDirsString);
smGD.clientPath[0] = 0; smGD.clientPath[0] = 0;
smGD.settingPath[0] = 0; smGD.settingPath[0] = 0;
smGD.resourcePath[0] = 0; smGD.resourcePath[0] = 0;
return(-1); return(-1);
} }
chmod(smGD.clientPath, 0755);
} }
strcat(smGD.clientPath, "/"); strcat(smGD.clientPath, "/");
@ -1284,7 +1311,13 @@ SetFontSavePath(char *langPtr)
smGD.fontPath[0] = 0; smGD.fontPath[0] = 0;
return(-1); return(-1);
} }
chmod(smGD.fontPath, 0755); status = chmod(smGD.fontPath, 0755);
if(status == -1)
{
PrintErrnoError(DtError, smNLS.cantCreateDirsString);
smGD.fontPath[0] = 0;
return(-1);
}
} }
return(0); return(0);
@ -1632,7 +1665,7 @@ TrimErrorlog( void )
len = strlen(home) + strlen(DtPERSONAL_CONFIG_DIRECTORY) + 2; len = strlen(home) + strlen(DtPERSONAL_CONFIG_DIRECTORY) + 2;
if (len > MAXPATHLEN) savePath = SM_REALLOC(savePath, len); if (len > MAXPATHLEN) savePath = SM_REALLOC(savePath, len);
sprintf(savePath, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY); snprintf(savePath, len - 1, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
/* /*
* If errorlog.old exists and it is not empty, delete * If errorlog.old exists and it is not empty, delete
@ -2352,11 +2385,11 @@ InitializeSpecificSession (
if (len > MAXPATHLEN) if (len > MAXPATHLEN)
alt_dir = XtRealloc(alt_dir, len + 1); alt_dir = XtRealloc(alt_dir, len + 1);
(void) sprintf (alt_dir, "%s/%s/%s/%s", snprintf(alt_dir, len, "%s/%s/%s/%s",
home, home,
DtPERSONAL_CONFIG_DIRECTORY, DtPERSONAL_CONFIG_DIRECTORY,
DtSM_SESSION_DIRECTORY, DtSM_SESSION_DIRECTORY,
SM_HOME_DIRECTORY); SM_HOME_DIRECTORY);
if (!SetAlternateSession (session_dir, if (!SetAlternateSession (session_dir,
alt_dir, alt_dir,
@ -2412,6 +2445,12 @@ InitializePaths (
char *db_file = (char *) XtMalloc(MAXPATHLEN); char *db_file = (char *) XtMalloc(MAXPATHLEN);
struct stat buf; struct stat buf;
if (!db_file)
{
PrintError(DtError, smNLS.cantMallocErrorString);
return;
}
smGD.savePath = _DtCreateDtDirs(disp); smGD.savePath = _DtCreateDtDirs(disp);
(void) sprintf (smGD.settingPath, "%s/%s/%s", (void) sprintf (smGD.settingPath, "%s/%s/%s",
@ -2434,7 +2473,7 @@ InitializePaths (
if ((stat(db_file, &buf)) == 0) if ((stat(db_file, &buf)) == 0)
(void) strcpy (smGD.clientPath, db_file); (void) strcpy (smGD.clientPath, db_file);
} }
if (db_file) XtFree(db_file); XtFree(db_file);
} }
@ -2472,6 +2511,13 @@ SetAlternateSession (
char *db_file2 = (char *) XtMalloc(MAXPATHLEN); char *db_file2 = (char *) XtMalloc(MAXPATHLEN);
struct stat buf; struct stat buf;
if (!db_file1 || !db_file2)
{
PrintError(DtError, smNLS.cantMallocErrorString);
return False;
}
if ((stat (session_dir, &buf)) != 0) { if ((stat (session_dir, &buf)) != 0) {
/* /*
* The requested dir does not exist, create it * The requested dir does not exist, create it
@ -2560,8 +2606,8 @@ SetAlternateSession (
SetSysDefaults (); SetSysDefaults ();
} }
if (db_file1) XtFree(db_file1); XtFree(db_file1);
if (db_file2) XtFree(db_file2); XtFree(db_file2);
return (True); return (True);
} }

View file

@ -162,7 +162,8 @@ static Boolean CanReAuthenticate(char *name, uid_t uid, char *passwd,
Boolean fail = False; Boolean fail = False;
*pwent = (name == NULL) ? getpwuid(uid) : getpwnam(name); *pwent = (name == NULL) ? getpwuid(uid) : getpwnam(name);
*spent = getspnam((*pwent)->pw_name); if (pwent)
*spent = getspnam((*pwent)->pw_name);
#ifdef JET_AUTHDEBUG #ifdef JET_AUTHDEBUG
fprintf(stderr, "CanReAuthenticate(): %s %s %s\n", fprintf(stderr, "CanReAuthenticate(): %s %s %s\n",

View file

@ -58,6 +58,7 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#ifdef _SUN_OS /* to get the define for NOFILE */ #ifdef _SUN_OS /* to get the define for NOFILE */
#include <sys/param.h> #include <sys/param.h>
#endif /* _SUN_OS */ #endif /* _SUN_OS */
@ -590,7 +591,7 @@ RestoreState( void )
fileSize = MAXLINE + 1; fileSize = MAXLINE + 1;
} }
line = (unsigned char *) malloc ((fileSize + 1) * sizeof(char *)); line = malloc(fileSize + 1);
if (line == NULL) if (line == NULL)
{ {
line = fallBackLine; line = fallBackLine;
@ -828,6 +829,8 @@ RestoreResources( Boolean errorHandlerInstalled, ... )
char *argv[20]; char *argv[20];
va_list args; va_list args;
#if 0
/* JET - this seems like a bad (and unused) idea */
/* /*
* Check for alternate resource loader. * Check for alternate resource loader.
*/ */
@ -835,6 +838,9 @@ RestoreResources( Boolean errorHandlerInstalled, ... )
{ {
pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res"; pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
} }
#else
pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
#endif
/* /*
* By convention, exec() wants arg0 to be the program name. Ex: if pgrm * By convention, exec() wants arg0 to be the program name. Ex: if pgrm
@ -1286,7 +1292,7 @@ RestoreSettings( void )
ptrSize += 50; ptrSize += 50;
restorePtrArray = (char **)SM_REALLOC((char *) restorePtrArray = (char **)SM_REALLOC((char *)
restorePtrArray, ptrSize * restorePtrArray, ptrSize *
sizeof(char **)); sizeof(char *));
if(restorePtrArray == NULL) if(restorePtrArray == NULL)
{ {
PrintErrnoError(DtError, smNLS.cantMallocErrorString); PrintErrnoError(DtError, smNLS.cantMallocErrorString);
@ -2065,6 +2071,7 @@ RestoreClients( void )
SM_FREE((char *) remoteBuf[i]); SM_FREE((char *) remoteBuf[i]);
} }
} }
free(displayName);
return(-1); return(-1);
} }
cmdPtr = NULL; cmdPtr = NULL;
@ -3497,14 +3504,20 @@ StartClient(
smRes.ignoreEnvironment, ','); smRes.ignoreEnvironment, ',');
} }
if (!defaultCwd) { if (!defaultCwd)
if (getenv ("HOME")) {
defaultCwd = strdup (getenv ("HOME")); char *tstr = getenv("HOME");
else if (tstr)
defaultCwd = getcwd (NULL, MAXPATHLEN + 1); {
int slen = strlen(tstr) + 1;
defaultCwd = XtCalloc(1, slen);
strncpy(defaultCwd, tstr, slen - 1);
}
else
defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
(void) gethostname (localHost, MAXHOSTNAMELEN); (void) gethostname (localHost, MAXHOSTNAMELEN);
} }
if (!cwd) { if (!cwd) {
cwdNull = True; cwdNull = True;

View file

@ -504,29 +504,36 @@ PruneSessionDirectory ()
*/ */
char * tmpName; char * tmpName;
char * tmp; int len, tfd;
tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2); len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
sprintf (tmpName, "%s.", smGD.restoreSession); + strlen("XXXXXX") + 3;
if (strlen (tmpName) > 5) { tmpName = XtCalloc (1, len);
tmpName[4] = '.'; sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath,
tmpName[5] = '\000'; smGD.restoreSession);
}
tmp = (char *) tempnam (smGD.savePath, tmpName);
sprintf (saveDir, "%s/%s", smGD.savePath, smGD.restoreSession); if ((tfd = mkstemp(tmpName)) == -1)
{
PrintErrnoError(DtError, smNLS.cantCreateDirsString);
}
else
{
close(tfd);
unlink(tmpName);
MoveDirectory (saveDir, tmp, False); sprintf (saveDir, "%s/%s",
MoveDirectory (oldestDir, saveDir, False); smGD.savePath, smGD.restoreSession);
sprintf (clientDB, "%s/%s/%s", smGD.savePath, MoveDirectory (saveDir, tmpName, False);
smGD.restoreSession, SM_CLIENT_FILE2); MoveDirectory (oldestDir, saveDir, False);
ExecuteDiscardCommands (clientDB); sprintf (clientDB, "%s/%s/%s", smGD.savePath,
smGD.restoreSession, SM_CLIENT_FILE2);
MoveDirectory (tmp, saveDir, True); ExecuteDiscardCommands (clientDB);
free (tmp); MoveDirectory (tmpName, saveDir, True);
}
XtFree (tmpName); XtFree (tmpName);
} }
@ -551,7 +558,7 @@ PruneSessionDirectory ()
if (((stat (saveDir, &buf)) == 0) && if (((stat (saveDir, &buf)) == 0) &&
S_ISDIR (buf.st_mode)) { S_ISDIR (buf.st_mode)) {
sprintf (clientDB, "rm -rf %s", saveDir); sprintf (clientDB, "/bin/rm -rf %s", saveDir);
SystemCmd (clientDB); SystemCmd (clientDB);
sprintf (oldestDir, "%s/%s", smGD.savePath, sprintf (oldestDir, "%s/%s", smGD.savePath,

View file

@ -907,9 +907,8 @@ CreateLockDialogWithCover(
*/ */
i = 0; i = 0;
envLog = getenv("LOGNAME"); envLog = getenv("LOGNAME");
lockMessage = XtMalloc(100 + strlen(envLog)); lockMessage = XtCalloc(1, 100 + strlen(envLog));
sprintf( snprintf(lockMessage, 100 + strlen(envLog) - 1,
lockMessage,
((char *)GETMESSAGE(18, 1, "Display locked by user %s.")), envLog); ((char *)GETMESSAGE(18, 1, "Display locked by user %s.")), envLog);
lockString = XmStringCreateLocalized(lockMessage); lockString = XmStringCreateLocalized(lockMessage);
XtSetArg(uiArgs[i], XmNtopAttachment, XmATTACH_POSITION); i++; XtSetArg(uiArgs[i], XmNtopAttachment, XmATTACH_POSITION); i++;

View file

@ -228,10 +228,8 @@ char *palette)
DEFAULT_PALETTE); DEFAULT_PALETTE);
} }
if (path != NULL) SRV_FREE(path);
SRV_FREE(path); SRV_FREE(palettePath);
if (palettePath != NULL)
SRV_FREE(palettePath);
return (paletteDef); return (paletteDef);
@ -372,6 +370,7 @@ ReadPaletteFile(
error_value = 1; error_value = 1;
unlink(palettePath); unlink(palettePath);
SRV_FREE(fullPath); SRV_FREE(fullPath);
close(fd);
return((struct _palette *) NULL); return((struct _palette *) NULL);
} }
} }

View file

@ -665,7 +665,7 @@ convert_pixel_set(
int i; int i;
char *converted; char *converted;
char *p; char *p;
int colormappingindex; int colormappingindex = 0;
const int colormapping [4][XmCO_MAX_NUM_COLORS] = { const int colormapping [4][XmCO_MAX_NUM_COLORS] = {
{0, 1, 2, 3, 4, 5, 6, 7}, /* XmCO_HIGH_COLOR */ {0, 1, 2, 3, 4, 5, 6, 7}, /* XmCO_HIGH_COLOR */