init: fix possible segfault if HOME not set

This commit is contained in:
Philippe Pepiot 2010-01-20 11:38:32 +01:00
parent c6b97b7892
commit 344d80206c

View File

@ -198,10 +198,18 @@ init_status(void)
{
int fd;
struct stat st;
char *home;
status_path = emalloc(strlen(getenv("HOME")) + strlen(DEF_STATUS) + 2, sizeof(char));
if(!(home = getenv("HOME")))
{
warnx("HOME not set, can't launch status.sh");
estatus = False;
return;
}
sprintf(status_path, "%s/"DEF_STATUS, getenv("HOME"));
status_path = emalloc(strlen(home) + strlen(DEF_STATUS) + 2, sizeof(char));
sprintf(status_path, "%s/"DEF_STATUS, home);
if(!(fd = open(status_path, O_RDONLY))
|| !fopen(status_path, "r"))