From 7c702bff6e031530ca572be4202fc08acdb0eb70 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Sat, 27 Dec 2014 19:01:30 -0700 Subject: [PATCH] dtsession/SmRestore: redo defaultCwd detection in StartClient() to be safer --- cde/programs/dtsession/SmRestore.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cde/programs/dtsession/SmRestore.c b/cde/programs/dtsession/SmRestore.c index 1f556b46..53835c25 100644 --- a/cde/programs/dtsession/SmRestore.c +++ b/cde/programs/dtsession/SmRestore.c @@ -58,6 +58,7 @@ #include #include #include +#include #ifdef _SUN_OS /* to get the define for NOFILE */ #include #endif /* _SUN_OS */ @@ -3503,14 +3504,20 @@ StartClient( smRes.ignoreEnvironment, ','); } - if (!defaultCwd) { - if (getenv ("HOME")) - defaultCwd = strndup (getenv("HOME"), MAXPATHLEN); - else - defaultCwd = getcwd (NULL, MAXPATHLEN + 1); - - (void) gethostname (localHost, MAXHOSTNAMELEN); - } + if (!defaultCwd) + { + char *tstr = getenv("HOME"); + if (tstr) + { + int slen = strlen(tstr) + 1; + defaultCwd = XtCalloc(1, slen); + strncpy(defaultCwd, tstr, slen - 1); + } + else + defaultCwd = getcwd (NULL, MAXPATHLEN + 1); + + (void) gethostname (localHost, MAXHOSTNAMELEN); + } if (!cwd) { cwdNull = True; -- 2.25.1