Fix startup crash with missing HOME or LOGNAME environment variables

Check whether setenv returns NULL and if so default to '~' for HOME
and 'default' for LOGNAME.

Signed-off-by: Sander Kleijwegt <sander@myowndomain.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Sander Kleijwegt 2015-08-19 17:59:35 +02:00 committed by Dirk Hohndel
parent 953470d945
commit b84e6dfc8a

View file

@ -55,7 +55,11 @@ const char *system_default_filename(void)
int len; int len;
home = getenv("HOME"); home = getenv("HOME");
if (!home)
home = "~";
user = getenv("LOGNAME"); user = getenv("LOGNAME");
if (!user)
user = "default";
len = strlen(home) + strlen(user) + 17; len = strlen(home) + strlen(user) + 17;
buffer = malloc(len); buffer = malloc(len);
snprintf(buffer, len, "%s/subsurface/%s.xml", home, user); snprintf(buffer, len, "%s/subsurface/%s.xml", home, user);