iptables: fix regression with unintended free in need_protomatch master
authorChristian Marangi <ansuelsmth@gmail.com>
Sat, 10 Jun 2023 16:56:11 +0000 (18:56 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Sat, 10 Jun 2023 19:08:23 +0000 (21:08 +0200)
commitbf1d5fdf623473419f8f738fc9071fee84cb13e5
treeec578500355d3363c47f8de6f2b102dc5f6ea759
parentffba75c9cd8f96ef34b7b3ab35315ce66ba8f37d
iptables: fix regression with unintended free in need_protomatch

xtables_find_match memory allocation is funny. It can return something
allocated in a linked list or return a just allocated match clone and is
never freed.

This caused confusion and made a broken patch where an unintended free
is done in the case of entry not cloned.
xtables_find_match have a way to comunicate that the entry is cloned by
returning a looping linked list where the next entry is the same entry.
We can use this to understand where the entry has to be freed.

Fixes: ffba75c9cd8f ("iptables: free xtables_match if found in need_protomatch")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Tested-by: Rui Salvaterra <rsalvaterra@gmail.com>
iptables.c