ctdb-tools: Fix heap-use-after-free problem
authorAmitay Isaacs <amitay@gmail.com>
Tue, 14 Oct 2014 06:52:55 +0000 (17:52 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 17 Oct 2014 10:56:02 +0000 (12:56 +0200)
Found by address sanitizer.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Fri Oct 17 12:56:02 CEST 2014 on sn-devel-104

ctdb/tools/ctdb.c

index 71dfc28779fb25d2c355c859ca6f308e7e30c226..c34e33d1e567d6ae0cbb92a3ff270ab4b601c8b7 100644 (file)
@@ -896,6 +896,7 @@ static int find_node_xpnn(void)
        TALLOC_CTX *mem_ctx = talloc_new(NULL);
        struct pnn_node *pnn_nodes;
        struct pnn_node *pnn_node;
+       int pnn;
 
        pnn_nodes = read_nodes_file(mem_ctx);
        if (pnn_nodes == NULL) {
@@ -906,8 +907,9 @@ static int find_node_xpnn(void)
 
        for(pnn_node=pnn_nodes;pnn_node;pnn_node=pnn_node->next) {
                if (ctdb_sys_have_ip(&pnn_node->addr)) {
+                       pnn = pnn_node->pnn;
                        talloc_free(mem_ctx);
-                       return pnn_node->pnn;
+                       return pnn;
                }
        }
 
@@ -1818,6 +1820,7 @@ find_other_host_for_public_ip(struct ctdb_context *ctdb, ctdb_sock_addr *addr)
        struct ctdb_all_public_ips *ips;
        struct ctdb_node_map *nodemap=NULL;
        int i, j, ret;
+       int pnn;
 
        ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, tmp_ctx, &nodemap);
        if (ret != 0) {
@@ -1843,8 +1846,9 @@ find_other_host_for_public_ip(struct ctdb_context *ctdb, ctdb_sock_addr *addr)
 
                for (j=0;j<ips->num;j++) {
                        if (ctdb_same_ip(addr, &ips->ips[j].addr)) {
+                               pnn = nodemap->nodes[i].pnn;
                                talloc_free(tmp_ctx);
-                               return nodemap->nodes[i].pnn;
+                               return pnn;
                        }
                }
                talloc_free(ips);