Merge branch 'master' into autotools-conversion

This commit is contained in:
Jon Trulson
2020-01-26 12:17:44 -07:00
8 changed files with 115 additions and 54 deletions

View File

@@ -176,10 +176,23 @@ getSessionPath(
/*
* NOTE: it is assumed that _DtCreateDtDirs() returns a buffer of
* size MAXPATHLEN+1. This allows us to avoid a extra alloc
* size MAXPATHLEN. This allows us to avoid a extra alloc
* and copy -- at the expense of code maintainability.
*
* JET - 2020. This is stupid. At least account for the strings
* you are adding further on down... This "solution" isn't great
* either. Real fix would be to have all callers pass in bufptr
* and len all the way down the chain instead of tmpPath.
*/
if ((strlen(tmpPath) + 1 + strlen(property)) > MAXPATHLEN) goto abort;
if ((strlen(tmpPath)
+ 1 /* "/" */
+ strlen(property)
+ 1 /* "/" */
+ ((*saveFile == NULL) ? strlen("dtXXXXXX") + 1 : strlen(*saveFile))
) >= MAXPATHLEN)
{
goto abort;
}
/*
* parse the property string and create directory if needed

View File

@@ -83,33 +83,32 @@ char *
_DtCreateDtDirs(
Display *display )
{
char *tmpPath;
char *tmpPath = NULL;
Boolean needSessionsDir = False;
Boolean useOldSession = False;
struct stat buf;
int status;
char *home;
char *sessionDir;
char *displayName;
char *home = NULL;
char *sessionDir = NULL;
char *displayName = NULL;
/*
* Sanity check - make sure there's an existing display
*/
if(!display)
return(NULL);
if ((home =getenv("HOME")) == NULL)
if ((home = getenv("HOME")) == NULL)
home = "";
tmpPath = XtCalloc(1, MAXPATHLEN + 1);
tmpPath = XtCalloc(1, MAXPATHLEN);
if(tmpPath == NULL)
return(NULL);
/*
* If the $HOME/.dt directory does not exist, create it
*/
strncpy(tmpPath, home, MAXPATHLEN);
strncat(tmpPath, "/" DtPERSONAL_CONFIG_DIRECTORY, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
status = stat(tmpPath, &buf);
if (status == -1) {
@@ -122,11 +121,10 @@ _DtCreateDtDirs(
}
/*
* Create the personal DB directory if it does not exist.
* Create the personal DB directory if it does not exist.
*/
strncpy(tmpPath, home, MAXPATHLEN);
strncat(tmpPath, "/" DtPERSONAL_DB_DIRECTORY, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_DB_DIRECTORY);
if ((status = stat (tmpPath, &buf)) == -1) {
if ((status = mkdir (tmpPath, 0000)) != -1)
(void) chmod (tmpPath, 0755);
@@ -135,8 +133,7 @@ _DtCreateDtDirs(
/*
* Create the personal tmp dir if it does not exist.
*/
strncpy(tmpPath, home, MAXPATHLEN);
strncat(tmpPath, "/" DtPERSONAL_TMP_DIRECTORY, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_TMP_DIRECTORY);
if ((status = stat (tmpPath, &buf)) == -1) {
if ((status = mkdir (tmpPath, 0000)) != -1)
@@ -173,12 +170,13 @@ _DtCreateDtDirs(
*/
if ((displayName = GetDisplayName (display)) != NULL) {
strncpy (tmpPath, home, MAXPATHLEN);
strncat (tmpPath, "/" DtPERSONAL_CONFIG_DIRECTORY, MAXPATHLEN);
strncat (tmpPath, "/", MAXPATHLEN);
strncat (tmpPath, displayName, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
home,
DtPERSONAL_CONFIG_DIRECTORY,
displayName);
free(displayName); /* CDExc22771 */
displayName = NULL;
if ((status = stat (tmpPath, &buf)) == -1) {
if ((status = mkdir (tmpPath, 0000)) != -1)
@@ -215,12 +213,13 @@ _DtCreateDtDirs(
*/
if ((displayName = GetDisplayName (display)) != NULL) {
strncpy (tmpPath, home, MAXPATHLEN);
strncat (tmpPath, "/" DtPERSONAL_CONFIG_DIRECTORY, MAXPATHLEN);
strncat (tmpPath, "/", MAXPATHLEN);
strncat (tmpPath, displayName, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
home,
DtPERSONAL_CONFIG_DIRECTORY,
displayName);
free(displayName); /* CDExc22771 */
displayName = NULL;
if ((status = stat(tmpPath, &buf)) != 0)
/*
@@ -238,9 +237,10 @@ _DtCreateDtDirs(
* If we don't have an old style directory - we check for a sessions
* directory, and create it if it doesn't exist
*/
strncpy (tmpPath, home, MAXPATHLEN);
strncat (tmpPath, "/" DtPERSONAL_CONFIG_DIRECTORY, MAXPATHLEN);
strncat (tmpPath, "/" DtSM_SESSION_DIRECTORY, MAXPATHLEN);
snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
home,
DtPERSONAL_CONFIG_DIRECTORY,
DtSM_SESSION_DIRECTORY);
if ((status = stat(tmpPath, &buf)) == -1) {
if ((status = mkdir(tmpPath, 0000)) == -1) {

View File

@@ -210,11 +210,7 @@ _DtSimpleError(
if (NULL == message) return;
Va_start(args, format);
#if defined(USE_SNPRINTF)
(void) vsnprintf(message, MESSAGE_BUFFER, format, args);
#else
(void) vsprintf(message, format, args);
#endif
va_end(args);
log_message(progName, help, message, severity, FALSE);
@@ -235,11 +231,7 @@ _DtSimpleErrnoError(
if (NULL == message) return;
Va_start(args, format);
#if defined(USE_SNPRINTF)
(void) vsnprintf(message, MESSAGE_BUFFER, format, args);
#else
(void) vsprintf(message, format, args);
#endif
va_end(args);
log_message(progName, help, message, severity, TRUE);