From: Guus Sliepen Date: Tue, 8 Sep 2009 16:18:36 +0000 (+0200) Subject: Replace asprintf() by xasprintf(). X-Git-Tag: release-1.0.10~44 X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=73d77dd416b87b7c4e9b6aa450f64846235cd2b4 Replace asprintf() by xasprintf(). --- diff --git a/src/conf.c b/src/conf.c index ce776804..d8a8d832 100644 --- a/src/conf.c +++ b/src/conf.c @@ -417,7 +417,7 @@ bool read_server_config() cp(); - asprintf(&fname, "%s/tinc.conf", confbase); + xasprintf(&fname, "%s/tinc.conf", confbase); x = read_config_file(config_tree, fname); if(x == -1) { /* System error: complain */ @@ -469,7 +469,7 @@ FILE *ask_and_open(const char *filename, const char *what) char *p; directory = get_current_dir_name(); - asprintf(&p, "%s/%s", directory, fn); + xasprintf(&p, "%s/%s", directory, fn); free(fn); free(directory); fn = p; diff --git a/src/connection.c b/src/connection.c index 9fd4002b..a2a188a6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -158,7 +158,7 @@ bool read_connection_config(connection_t *c) cp(); - asprintf(&fname, "%s/hosts/%s", confbase, c->name); + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); x = read_config_file(c->config_tree, fname); free(fname); diff --git a/src/graph.c b/src/graph.c index 85643585..a267f052 100644 --- a/src/graph.c +++ b/src/graph.c @@ -57,6 +57,7 @@ #include "process.h" #include "subnet.h" #include "utils.h" +#include "xalloc.h" static bool graph_changed = true; @@ -269,18 +270,18 @@ void sssp_bfs(void) n->mtuevent = NULL; } - asprintf(&envp[0], "NETNAME=%s", netname ? : ""); - asprintf(&envp[1], "DEVICE=%s", device ? : ""); - asprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - asprintf(&envp[3], "NODE=%s", n->name); + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NODE=%s", n->name); sockaddr2str(&n->address, &address, &port); - asprintf(&envp[4], "REMOTEADDRESS=%s", address); - asprintf(&envp[5], "REMOTEPORT=%s", port); + xasprintf(&envp[4], "REMOTEADDRESS=%s", address); + xasprintf(&envp[5], "REMOTEPORT=%s", port); envp[6] = NULL; execute_script(n->status.reachable ? "host-up" : "host-down", envp); - asprintf(&name, + xasprintf(&name, n->status.reachable ? "hosts/%s-up" : "hosts/%s-down", n->name); execute_script(name, envp); @@ -331,7 +332,7 @@ void dump_graph(void) if(filename[0] == '|') { file = popen(filename + 1, "w"); } else { - asprintf(&tmpname, "%s.new", filename); + xasprintf(&tmpname, "%s.new", filename); file = fopen(tmpname, "w"); } diff --git a/src/net.c b/src/net.c index 7f17252d..4a2af954 100644 --- a/src/net.c +++ b/src/net.c @@ -466,7 +466,7 @@ int main_loop(void) for(node = connection_tree->head; node; node = node->next) { c = node->data; - asprintf(&fname, "%s/hosts/%s", confbase, c->name); + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); if(stat(fname, &s) || s.st_mtime > last_config_check) terminate_connection(c, c->status.active); free(fname); diff --git a/src/net_setup.c b/src/net_setup.c index 94e25b62..4eef68ed 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -113,7 +113,7 @@ bool read_rsa_public_key(connection_t *c) /* Else, check if a harnessed public key is in the config file */ - asprintf(&fname, "%s/hosts/%s", confbase, c->name); + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); fp = fopen(fname, "r"); if(fp) { @@ -128,7 +128,7 @@ bool read_rsa_public_key(connection_t *c) /* Try again with PEM_read_RSA_PUBKEY. */ - asprintf(&fname, "%s/hosts/%s", confbase, c->name); + xasprintf(&fname, "%s/hosts/%s", confbase, c->name); fp = fopen(fname, "r"); if(fp) { @@ -171,7 +171,7 @@ bool read_rsa_private_key(void) } if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname)) - asprintf(&fname, "%s/rsa_key.priv", confbase); + xasprintf(&fname, "%s/rsa_key.priv", confbase); fp = fopen(fname, "r"); @@ -228,8 +228,8 @@ bool setup_myself(void) myself->connection = new_connection(); init_configuration(&myself->connection->config_tree); - asprintf(&myself->hostname, _("MYSELF")); - asprintf(&myself->connection->hostname, _("MYSELF")); + xasprintf(&myself->hostname, _("MYSELF")); + xasprintf(&myself->connection->hostname, _("MYSELF")); myself->connection->options = 0; myself->connection->protocol_version = PROT_CURRENT; @@ -257,7 +257,7 @@ bool setup_myself(void) return false; if(!get_config_string(lookup_config(myself->connection->config_tree, "Port"), &myport)) - asprintf(&myport, "655"); + xasprintf(&myport, "655"); /* Read in all the subnets specified in the host configuration file */ @@ -433,10 +433,10 @@ bool setup_myself(void) return false; /* Run tinc-up script to further initialize the tap interface */ - asprintf(&envp[0], "NETNAME=%s", netname ? : ""); - asprintf(&envp[1], "DEVICE=%s", device ? : ""); - asprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - asprintf(&envp[3], "NAME=%s", myself->name); + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NAME=%s", myself->name); envp[4] = NULL; execute_script("tinc-up", envp); @@ -571,10 +571,10 @@ void close_network_connections(void) close(listen_socket[i].udp); } - asprintf(&envp[0], "NETNAME=%s", netname ? : ""); - asprintf(&envp[1], "DEVICE=%s", device ? : ""); - asprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - asprintf(&envp[3], "NAME=%s", myself->name); + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NAME=%s", myself->name); envp[4] = NULL; exit_requests(); diff --git a/src/net_socket.c b/src/net_socket.c index 865df786..8df9f380 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -367,7 +367,7 @@ begin: get_config_string(c->outgoing->cfg, &address); if(!get_config_string(lookup_config(c->config_tree, "Port"), &port)) - asprintf(&port, "655"); + xasprintf(&port, "655"); c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM); free(address); diff --git a/src/netutl.c b/src/netutl.c index 20648605..909441e1 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -128,7 +128,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) cp(); if(sa->sa.sa_family == AF_UNKNOWN) { - asprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port); + xasprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port); return str; } @@ -139,7 +139,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) gai_strerror(err)); } - asprintf(&str, _("%s port %s"), address, port); + xasprintf(&str, _("%s port %s"), address, port); return str; } diff --git a/src/process.c b/src/process.c index c2940bc5..28bba02d 100644 --- a/src/process.c +++ b/src/process.c @@ -371,9 +371,9 @@ bool execute_script(const char *name, char **envp) cp(); #ifndef HAVE_MINGW - len = asprintf(&scriptname, "\"%s/%s\"", confbase, name); + len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name); #else - len = asprintf(&scriptname, "\"%s/%s.bat\"", confbase, name); + len = xasprintf(&scriptname, "\"%s/%s.bat\"", confbase, name); #endif if(len < 0) return false; diff --git a/src/protocol.c b/src/protocol.c index 2e93cff4..85133954 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -75,7 +75,7 @@ bool send_request(connection_t *c, const char *format, ...) cp(); - /* Use vsnprintf instead of vasprintf: faster, no memory + /* Use vsnprintf instead of vxasprintf: faster, no memory fragmentation, cleanup is automatic, and there is a limit on the input buffer anyway */ diff --git a/src/solaris/device.c b/src/solaris/device.c index 748b5459..f76bbbd5 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -100,7 +100,7 @@ bool setup_device(void) } if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) - asprintf(&iface, "tun%d", ppa); + xasprintf(&iface, "tun%d", ppa); device_info = _("Solaris tun device"); diff --git a/src/subnet.c b/src/subnet.c index 9547829f..334729db 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -480,15 +480,15 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { char netstr[MAXNETSTR + 7] = "SUBNET="; char *name, *address, *port; - asprintf(&envp[0], "NETNAME=%s", netname ? : ""); - asprintf(&envp[1], "DEVICE=%s", device ? : ""); - asprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - asprintf(&envp[3], "NODE=%s", owner->name); + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NODE=%s", owner->name); if(owner != myself) { sockaddr2str(&owner->address, &address, &port); - asprintf(&envp[4], "REMOTEADDRESS=%s", address); - asprintf(&envp[5], "REMOTEPORT=%s", port); + xasprintf(&envp[4], "REMOTEADDRESS=%s", address); + xasprintf(&envp[5], "REMOTEPORT=%s", port); envp[6] = netstr; envp[7] = NULL; } else { diff --git a/src/tincd.c b/src/tincd.c index da3c33fa..a13e2661 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -337,7 +337,7 @@ static bool keygen(int bits) } else fprintf(stderr, _("Done.\n")); - asprintf(&filename, "%s/rsa_key.priv", confbase); + xasprintf(&filename, "%s/rsa_key.priv", confbase); f = ask_and_open(filename, _("private RSA key")); if(!f) @@ -356,9 +356,9 @@ static bool keygen(int bits) free(filename); if(name) - asprintf(&filename, "%s/hosts/%s", confbase, name); + xasprintf(&filename, "%s/hosts/%s", confbase, name); else - asprintf(&filename, "%s/rsa_key.pub", confbase); + xasprintf(&filename, "%s/rsa_key.pub", confbase); f = ask_and_open(filename, _("public RSA key")); @@ -389,7 +389,7 @@ static void make_names(void) #endif if(netname) - asprintf(&identname, "tinc.%s", netname); + xasprintf(&identname, "tinc.%s", netname); else identname = xstrdup("tinc"); @@ -397,12 +397,12 @@ static void make_names(void) if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) { if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) { if(!logfilename) - asprintf(&logfilename, "%s/log/%s.log", identname); + xasprintf(&logfilename, "%s/log/%s.log", identname); if(!confbase) { if(netname) - asprintf(&confbase, "%s/%s", installdir, netname); + xasprintf(&confbase, "%s/%s", installdir, netname); else - asprintf(&confbase, "%s", installdir); + xasprintf(&confbase, "%s", installdir); } } RegCloseKey(key); @@ -412,19 +412,19 @@ static void make_names(void) #endif if(!pidfilename) - asprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname); + xasprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname); if(!logfilename) - asprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname); + xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname); if(netname) { if(!confbase) - asprintf(&confbase, CONFDIR "/tinc/%s", netname); + xasprintf(&confbase, CONFDIR "/tinc/%s", netname); else logger(LOG_INFO, _("Both netname and configuration directory given, using the latter...")); } else { if(!confbase) - asprintf(&confbase, CONFDIR "/tinc"); + xasprintf(&confbase, CONFDIR "/tinc"); } } diff --git a/src/uml_socket/device.c b/src/uml_socket/device.c index 62a6f2eb..de0b4a55 100644 --- a/src/uml_socket/device.c +++ b/src/uml_socket/device.c @@ -71,7 +71,7 @@ bool setup_device(void) cp(); if(!get_config_string(lookup_config(config_tree, "Device"), &device)) - asprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname); + xasprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname); get_config_string(lookup_config(config_tree, "Interface"), &iface);