From: Guus Sliepen Date: Tue, 6 May 2014 20:12:47 +0000 (+0200) Subject: Fix a few more issues found by Coverity. X-Git-Tag: release-1.0.24~6 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=5eb72b73d3cd842e71e525413a46a55644ac3583;p=tinc Fix a few more issues found by Coverity. --- diff --git a/src/avl_tree.c b/src/avl_tree.c index 4b237560..22d7ff5d 100644 --- a/src/avl_tree.c +++ b/src/avl_tree.c @@ -168,14 +168,12 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) child->right->parent = child; gchild->right = node; - if(gchild->right) - gchild->right->parent = gchild; + gchild->right->parent = gchild; gchild->left = child; - if(gchild->left) - gchild->left->parent = gchild; - *superparent = gchild; + gchild->left->parent = gchild; + *superparent = gchild; gchild->parent = parent; #ifdef AVL_COUNT node->count = AVL_CALC_COUNT(node); @@ -224,8 +222,7 @@ static void avl_rebalance(avl_tree_t *tree, avl_node_t *node) child->left->parent = child; gchild->left = node; - if(gchild->left) - gchild->left->parent = gchild; + gchild->left->parent = gchild; gchild->right = child; gchild->right->parent = gchild; diff --git a/src/net_setup.c b/src/net_setup.c index 9f25fb95..60335fd0 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -578,6 +578,7 @@ static bool setup_myself(void) { addressfamily = AF_UNSPEC; else { logger(LOG_ERR, "Invalid address family!"); + free(afname); return false; } free(afname); @@ -595,6 +596,7 @@ static bool setup_myself(void) { if(!myself->incipher) { logger(LOG_ERR, "Unrecognized cipher type!"); + free(cipher); return false; } } diff --git a/src/net_socket.c b/src/net_socket.c index cfcf1c39..4beb665a 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -102,7 +102,6 @@ static bool bind_to_interface(int sd) { return false; } - free(iface); #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */ logger(LOG_WARNING, "%s not supported on this platform", "BindToInterface"); #endif diff --git a/src/raw_socket_device.c b/src/raw_socket_device.c index c61e43c9..a5cd835c 100644 --- a/src/raw_socket_device.c +++ b/src/raw_socket_device.c @@ -62,10 +62,11 @@ static bool setup_device(void) { memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); + ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0; + if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) { close(device_fd); - logger(LOG_ERR, "Can't find interface %s: %s", iface, - strerror(errno)); + logger(LOG_ERR, "Can't find interface %s: %s", ifr.ifr_ifrn.ifrn_name, strerror(errno)); return false; } @@ -75,7 +76,7 @@ static bool setup_device(void) { sa.sll_ifindex = ifr.ifr_ifindex; if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof(sa))) { - logger(LOG_ERR, "Could not bind %s to %s: %s", device, iface, strerror(errno)); + logger(LOG_ERR, "Could not bind %s to %s: %s", device, ifr.ifr_ifrn.ifrn_name, strerror(errno)); return false; } diff --git a/src/xmalloc.c b/src/xmalloc.c index 1e400173..a6874332 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -115,7 +115,7 @@ char *xstrdup(const char *s) p = strdup(s); if(!p) - xalloc_fail ((int)strlen(s)); + xalloc_fail (s ? (int)strlen(s) : 0); return p; }