Fix a few more issues found by Coverity.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 6 May 2014 20:12:47 +0000 (22:12 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 6 May 2014 20:12:47 +0000 (22:12 +0200)
src/avl_tree.c
src/net_setup.c
src/net_socket.c
src/raw_socket_device.c
src/xmalloc.c

index 4b237560423f379b72507960eed1bb7ccef50628..22d7ff5d887931a9413e713e1c2534181bdcb1c4 100644 (file)
@@ -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;
index 9f25fb9598d26e1bcbc478c31f064413494730df..60335fd08df50955cc243f54217de043a6143d05 100644 (file)
@@ -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;
                        }
                }
index cfcf1c39cded444cac8049c4910028e5116e2537..4beb665a2346d8f5eb6508af8fa79214b0db7b22 100644 (file)
@@ -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
index c61e43c9c810153337d43fbc141da5caed1d7ede..a5cd835c26294583f5e3fd23b91185a3cad76bf9 100644 (file)
@@ -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;
        }
 
index 1e4001738aca3b59a2408759d23a199607019c12..a6874332091f1685ba14f863b19ca0d286ecfc77 100644 (file)
@@ -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;
 }