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

dtsession/SmRestore: redo defaultCwd detection in StartClient() to be safer

This commit is contained in:
Jon Trulson 2014-12-27 19:01:30 -07:00
parent a657f302f7
commit 7c702bff6e

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 */
@ -3503,14 +3504,20 @@ StartClient(
smRes.ignoreEnvironment, ','); smRes.ignoreEnvironment, ',');
} }
if (!defaultCwd) { if (!defaultCwd)
if (getenv ("HOME")) {
defaultCwd = strndup (getenv("HOME"), MAXPATHLEN); char *tstr = getenv("HOME");
else if (tstr)
defaultCwd = getcwd (NULL, MAXPATHLEN + 1); {
int slen = strlen(tstr) + 1;
(void) gethostname (localHost, MAXHOSTNAMELEN); defaultCwd = XtCalloc(1, slen);
} strncpy(defaultCwd, tstr, slen - 1);
}
else
defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
(void) gethostname (localHost, MAXHOSTNAMELEN);
}
if (!cwd) { if (!cwd) {
cwdNull = True; cwdNull = True;