]> git.meshlink.io Git - meshlink/commitdiff
Fix segfault when Name = $HOST but $HOST is not set.
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 27 Sep 2013 09:36:46 +0000 (11:36 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 27 Sep 2013 09:36:46 +0000 (11:36 +0200)
Conflicts:
src/net_setup.c

src/net_setup.c

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