]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: Fix memleak of matches' udata
authorPhil Sutter <phil@nwl.cc>
Wed, 31 Jan 2024 13:58:17 +0000 (14:58 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 1 Feb 2024 13:51:30 +0000 (14:51 +0100)
If the extension specifies a non-zero udata_size, field 'udata' points
to an allocated buffer which needs to be freed upon extension deinit.

Interestingly, this bug was identified by ASAN and missed by valgrind.

Fixes: 2dba676b68ef8 ("extensions: support for per-extension instance "global" variable space")
Signed-off-by: Phil Sutter <phil@nwl.cc>
libxtables/xtables.c

index b4339e8d312750351ef8e3cc5a94ccd3231a9007..856bfae804ea9bae4ffb5575ed53289d8aa1cbe5 100644 (file)
@@ -1420,6 +1420,10 @@ void xtables_rule_matches_free(struct xtables_rule_match **matches)
                        free(matchp->match->m);
                        matchp->match->m = NULL;
                }
+               if (matchp->match->udata_size) {
+                       free(matchp->match->udata);
+                       matchp->match->udata = NULL;
+               }
                if (matchp->match == matchp->match->next) {
                        free(matchp->match);
                        matchp->match = NULL;