Fix segfault when Name = $HOST but $HOST is not set.
Conflicts: src/net_setup.c
This commit is contained in:
parent
22d804d446
commit
68e3efe349
1 changed files with 4 additions and 3 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue