summaryrefslogtreecommitdiff
path: root/src/ipcpd/udp
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-05-28 11:51:35 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2018-05-28 12:53:36 +0200
commit1bee8b3d288bc2c26432b8e675b18e482a98255e (patch)
tree0535f99d4b4cc640b1945f779cf50acc8e90a400 /src/ipcpd/udp
parentd537083d00facc5f0b53b5a7ffaa417786bdfc1f (diff)
downloadouroboros-1bee8b3d288bc2c26432b8e675b18e482a98255e.tar.gz
ouroboros-1bee8b3d288bc2c26432b8e675b18e482a98255e.zip
build: Check for variable length arrays
The clang and gcc compilers don't complain about variable length arrays using the -c89 flag unless the flag -Wvla or -Wpedantic is set. This also fixes a memleak and two false positive uninitialized variable warnings reported by the clang static analyzer in graph.c. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/ipcpd/udp')
-rw-r--r--src/ipcpd/udp/main.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index 26f993ce..8341aac1 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -788,7 +788,11 @@ static int ipcp_udp_reg(const uint8_t * hash)
uint32_t dns_addr;
uint32_t ip_addr;
#endif
- char hashstr[ipcp_dir_hash_strlen() + 1];
+ char * hashstr;
+
+ hashstr = malloc(ipcp_dir_hash_strlen() + 1);
+ if (hashstr == NULL)
+ return -1;
assert(hash);
@@ -797,6 +801,7 @@ static int ipcp_udp_reg(const uint8_t * hash)
if (shim_data_reg_add_entry(udp_data.shim_data, hash)) {
log_err("Failed to add " HASH_FMT " to local registry.",
HASH_VAL(hash));
+ free(hashstr);
return -1;
}
@@ -810,11 +815,13 @@ static int ipcp_udp_reg(const uint8_t * hash)
if (inet_ntop(AF_INET, &ip_addr,
ipstr, INET_ADDRSTRLEN) == NULL) {
+ free(hashstr);
return -1;
}
if (inet_ntop(AF_INET, &dns_addr,
dnsstr, INET_ADDRSTRLEN) == NULL) {
+ free(hashstr);
return -1;
}
@@ -823,12 +830,15 @@ static int ipcp_udp_reg(const uint8_t * hash)
if (ddns_send(cmd)) {
shim_data_reg_del_entry(udp_data.shim_data, hash);
+ free(hashstr);
return -1;
}
}
#endif
log_dbg("Registered " HASH_FMT ".", HASH_VAL(hash));
+ free(hashstr);
+
return 0;
}
@@ -840,10 +850,14 @@ static int ipcp_udp_unreg(const uint8_t * hash)
char cmd[100];
uint32_t dns_addr;
#endif
- char hashstr[ipcp_dir_hash_strlen() + 1];
+ char * hashstr;
assert(hash);
+ hashstr = malloc(ipcp_dir_hash_strlen() + 1);
+ if (hashstr == NULL)
+ return -1;
+
ipcp_hash_str(hashstr, hash);
#ifdef HAVE_DDNS
@@ -854,6 +868,7 @@ static int ipcp_udp_unreg(const uint8_t * hash)
if (dns_addr != 0) {
if (inet_ntop(AF_INET, &dns_addr, dnsstr, INET_ADDRSTRLEN)
== NULL) {
+ free(hashstr);
return -1;
}
sprintf(cmd, "server %s\nupdate delete %s A\nsend\nquit\n",
@@ -867,24 +882,32 @@ static int ipcp_udp_unreg(const uint8_t * hash)
log_dbg("Unregistered " HASH_FMT ".", HASH_VAL(hash));
+ free(hashstr);
+
return 0;
}
static int ipcp_udp_query(const uint8_t * hash)
{
uint32_t ip_addr = 0;
+ char * hashstr;
struct hostent * h;
#ifdef HAVE_DDNS
uint32_t dns_addr = 0;
#endif
- char hashstr[ipcp_dir_hash_strlen() + 1];
assert(hash);
+ hashstr = malloc(ipcp_dir_hash_strlen() + 1);
+ if (hashstr == NULL)
+ return -ENOMEM;
+
ipcp_hash_str(hashstr, hash);
- if (shim_data_dir_has(udp_data.shim_data, hash))
+ if (shim_data_dir_has(udp_data.shim_data, hash)) {
+ free(hashstr);
return 0;
+ }
#ifdef HAVE_DDNS
dns_addr = udp_data.dns_addr;
@@ -893,6 +916,7 @@ static int ipcp_udp_query(const uint8_t * hash)
ip_addr = ddns_resolve(hashstr, dns_addr);
if (ip_addr == 0) {
log_dbg("Could not resolve %s.", hashstr);
+ free(hashstr);
return -1;
}
} else {
@@ -900,6 +924,7 @@ static int ipcp_udp_query(const uint8_t * hash)
h = gethostbyname(hashstr);
if (h == NULL) {
log_dbg("Could not resolve %s.", hashstr);
+ free(hashstr);
return -1;
}
@@ -910,9 +935,12 @@ static int ipcp_udp_query(const uint8_t * hash)
if (shim_data_dir_add_entry(udp_data.shim_data, hash, ip_addr)) {
log_err("Failed to add directory entry.");
+ free(hashstr);
return -1;
}
+ free(hashstr);
+
return 0;
}