Fix segfault when Name = $HOST but $HOST is not set.

Conflicts:
	src/net_setup.c
This commit is contained in:
Guus Sliepen 2013-09-27 11:36:46 +02:00
parent 22d804d446
commit 68e3efe349

View file

@ -411,17 +411,18 @@ char *get_name(void) {
if(*name == '$') { if(*name == '$') {
char *envname = getenv(name + 1); char *envname = getenv(name + 1);
char hostname[32] = "";
if(!envname) { if(!envname) {
if(strcmp(name + 1, "HOST")) { if(strcmp(name + 1, "HOST")) {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1); logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1);
return false; return false;
} }
char envname[32]; if(gethostname(hostname, sizeof hostname) || !*hostname) {
if(gethostname(envname, 32)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno));
return false; return false;
} }
envname[31] = 0; hostname[31] = 0;
envname = hostname;
} }
free(name); free(name);
name = xstrdup(envname); name = xstrdup(envname);