From 344d80206c6771e31d1ab7c4b9938dbe9257c2dd Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Wed, 20 Jan 2010 11:38:32 +0100 Subject: [PATCH] init: fix possible segfault if HOME not set --- src/init.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index da90df8..69571a6 100644 --- a/src/init.c +++ b/src/init.c @@ -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"))