]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: fix memory leak when listing rules
authorEric Leblond <eric@regit.org>
Mon, 10 Jul 2017 22:32:49 +0000 (00:32 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 17 Jul 2017 15:20:33 +0000 (17:20 +0200)
When listing rules we were calling strdup on the table name
but variable was just used locally.

Found via `nft list ruleset` run with ASAN:

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x45cca0 in __interceptor_strdup (/usr/local/sbin/nft+0x45cca0)
    #1 0x593c71 in xstrdup /home/eric/git/netfilter/nftables/src/utils.c:75:8
    #2 0x513b34 in do_list_ruleset /home/eric/git/netfilter/nftables/src/rule.c:1388:23
    #3 0x50e178 in do_command_list /home/eric/git/netfilter/nftables/src/rule.c:1500:10
    #4 0x50d3ea in do_command /home/eric/git/netfilter/nftables/src/rule.c:1696:10
    #5 0x5061ae in nft_netlink /home/eric/git/netfilter/nftables/src/main.c:207:9
    #6 0x505b87 in nft_run /home/eric/git/netfilter/nftables/src/main.c:255:8
    #7 0x50771f in main /home/eric/git/netfilter/nftables/src/main.c:392:6
    #8 0x7fa1f326d2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index b0b64ffe5344207654e07629dde3e2db79c5326e..7a429bb2f1f2d51f07c821e4c91005ab79aec049 100644 (file)
@@ -1388,12 +1388,14 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)
                        continue;
 
                cmd->handle.family = table->handle.family;
-               cmd->handle.table = xstrdup(table->handle.table);
+               cmd->handle.table = table->handle.table;
 
                if (do_list_table(ctx, cmd, table) < 0)
                        return -1;
        }
 
+       cmd->handle.table = NULL;
+
        return 0;
 }