]> git.ipfire.org Git - thirdparty/nftables.git/commit
Avoid a memleak with 'reset rules' command
authorPhil Sutter <phil@nwl.cc>
Mon, 20 Mar 2023 09:03:13 +0000 (10:03 +0100)
committerPhil Sutter <phil@nwl.cc>
Mon, 20 Mar 2023 22:13:39 +0000 (23:13 +0100)
commit5adb51190c967d28ef7f23464807f7bc86636978
treed8d564b6d9cf5576d9413f9d17bb53b97d55a269
parent4649abed1d57fb8f99f9caf06acc1eca2785926e
Avoid a memleak with 'reset rules' command

Like other 'reset' commands, 'reset rules' also lists the (part of the)
ruleset which was affected to give users a chance to store the zeroed
values. Therefore do_command_reset() calls do_command_list(). This in
turn calls do_list_ruleset() for CMD_OBJ_RULES which wasn't prepared for
values stored in cmd->handle other than a possible family value and thus
freely reused the pointers as scratch area for the do_list_table() call
whiich in the past fetched each table's data directly from kernel.

Meanwhile ruleset listing code has been integrated into the common
caching logic, the 'cmd' pointer became unused by do_list_table(). The
temporary cmd->handle manipulation is not needed anymore, dropping it
prevents a memleak caused by overwriting of allocated table name
pointer.

Fixes: 1694df2de79f3 ("Implement 'reset rule' and 'reset rules' commands")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/rule.c