1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

dtsession: A few extra snprintf's for buffer safety

This commit is contained in:
Peter Howkins 2018-04-29 02:11:23 +01:00
parent e14e74231c
commit f2c6a48d72
3 changed files with 8 additions and 8 deletions

View file

@ -1106,7 +1106,7 @@ SetSavePath(
* runs a Current session and saves the session. * runs a Current session and saves the session.
*/ */
strcpy (savedDir, smGD.clientPath); strcpy (savedDir, smGD.clientPath);
sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION); snprintf(smGD.etcPath, sizeof(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)
{ {
@ -1180,7 +1180,7 @@ SetSavePath(
*/ */
char * tmpName; char * tmpName;
sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION); snprintf(smGD.etcPath, sizeof(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)
{ {
@ -1189,7 +1189,7 @@ SetSavePath(
len = strlen(smGD.savePath) + strlen(smGD.restoreSession) len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
+ strlen("XXXXXX") + 3; + strlen("XXXXXX") + 3;
tmpName = (char *) XtCalloc(1, len); tmpName = (char *) XtCalloc(1, len);
sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath, snprintf(tmpName, len, "%s/%s.XXXXXX", smGD.savePath,
smGD.restoreSession); smGD.restoreSession);
strcpy (savedOldDir, smGD.etcPath); strcpy (savedOldDir, smGD.etcPath);
@ -1702,7 +1702,7 @@ TrimErrorlog( void )
*/ */
if (len + strlen(DtERRORLOG_FILE) > MAXPATHLEN) if (len + strlen(DtERRORLOG_FILE) > MAXPATHLEN)
checkPath1 = SM_REALLOC(savePath, len + strlen(DtERRORLOG_FILE)); checkPath1 = SM_REALLOC(savePath, len + strlen(DtERRORLOG_FILE));
sprintf(checkPath1, "%s/%s", savePath, DtERRORLOG_FILE); snprintf(checkPath1, len + strlen(DtERRORLOG_FILE), "%s/%s", savePath, DtERRORLOG_FILE);
status = stat(checkPath1, &buf); status = stat(checkPath1, &buf);
if((status != -1) && (buf.st_size > 0)) if((status != -1) && (buf.st_size > 0))

View file

@ -3512,7 +3512,7 @@ StartClient(
{ {
int slen = strlen(tstr) + 1; int slen = strlen(tstr) + 1;
defaultCwd = XtCalloc(1, slen); defaultCwd = XtCalloc(1, slen);
strncpy(defaultCwd, tstr, slen - 1); snprintf(defaultCwd, slen, "%s", tstr);
} }
else else
defaultCwd = getcwd (NULL, MAXPATHLEN + 1); defaultCwd = getcwd (NULL, MAXPATHLEN + 1);

View file

@ -238,10 +238,10 @@ Boolean InitXSMP ( )
if (!env) { if (!env) {
free (networkIds); free (networkIds);
PostXSMPFailureDialog (XSMP_FAILURE_MALLOC, False); PostXSMPFailureDialog (XSMP_FAILURE_MALLOC, False);
} else {
(void) sprintf (env, "%s=%s", SM_SESSION_MANAGER, networkIds);
(void) putenv (env);
} }
(void) sprintf (env, "%s=%s", SM_SESSION_MANAGER, networkIds);
(void) putenv (env);
PutSessionManagerOnRootWindow (networkIds); PutSessionManagerOnRootWindow (networkIds);