From 5eb72b73d3cd842e71e525413a46a55644ac3583 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 6 May 2014 22:12:47 +0200 Subject: [PATCH] Fix a few more issues found by Coverity. --- src/avl_tree.c | 11 ++++------- src/net_setup.c | 2 ++ src/net_socket.c | 1 - src/raw_socket_device.c | 7 ++++--- src/xmalloc.c | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/avl_tree.c b/src/avl_tree.c index 4b23756..22d7ff5 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 9f25fb9..60335fd 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 cfcf1c3..4beb665 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 c61e43c..a5cd835 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 1e40017..a687433 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; } -- 2.25.1