Reformat the code using astyle.
[tinc] / src / conf.c
index 5304ab5..67e1426 100644 (file)
@@ -80,18 +80,9 @@ config_t *new_config(void) {
 }
 
 void free_config(config_t *cfg) {
-       if(cfg->variable) {
-               free(cfg->variable);
-       }
-
-       if(cfg->value) {
-               free(cfg->value);
-       }
-
-       if(cfg->file) {
-               free(cfg->file);
-       }
-
+       free(cfg->variable);
+       free(cfg->value);
+       free(cfg->file);
        free(cfg);
 }
 
@@ -203,7 +194,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) {
 }
 
 bool get_config_subnet(const config_t *cfg, subnet_t **result) {
-       subnet_t subnet = {NULL};
+       subnet_t subnet = {0};
 
        if(!cfg) {
                return false;
@@ -215,20 +206,14 @@ bool get_config_subnet(const config_t *cfg, subnet_t **result) {
                return false;
        }
 
-       /* Teach newbies what subnets are... */
-
-       if(((subnet.type == SUBNET_IPV4)
-                       && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address)))
-                       || ((subnet.type == SUBNET_IPV6)
-                           && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
-                      cfg->variable, cfg->file, cfg->line);
-               return false;
+       if(subnetcheck(subnet)) {
+               *(*result = new_subnet()) = subnet;
+               return true;
        }
 
-       *(*result = new_subnet()) = subnet;
-
-       return true;
+       logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d",
+              cfg->variable, cfg->file, cfg->line);
+       return false;
 }
 
 /*
@@ -433,7 +418,11 @@ bool read_server_config(void) {
 
                                // And we try to read the ones that end with ".conf"
                                if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) {
-                                       snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name);
+                                       if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) {
+                                               logger(DEBUG_ALWAYS, LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name);
+                                               return false;
+                                       }
+
                                        x = read_config_file(config_tree, fname, true);
                                }
                        }