Skip to contentSkip to conversation

libnftables: Zero ctx->vars after freeing it

PATCH In review Phil Sutter 1 participant 2 messages Sep 3, 2024 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 libnftables: Zero ctx->vars after freeing it

Leaving the invalid pointer value in place will cause a double-free when users call nft_ctx_clear_vars() first, then nft_ctx_free(). Moreover, nft_ctx_add_var() passes the pointer to mrealloc() and thus assumes it to be either NULL or valid.

Fixes 9edaa6a51eab4 ("src: add --define key=value")
---
 src/libnftables.c | 1 +
 1 file changed, 1 insertion(+)
src/libnftables.c +1 -0
index 7fc81515258d1..2ae215013cb0a 100644
@@ -160,6 +160,7 @@ void nft_ctx_clear_vars(struct nft_ctx *ctx)
 	}
 	ctx->num_vars = 0;
 	free(ctx->vars);
+	ctx->vars = NULL;
 }
 
 EXPORT_SYMBOL(nft_ctx_add_include_path);
Signature · 1 line
2.43.0
author reviewer
#1 lore raw
Quoted 8 lines · Phil Sutter

Leaving the invalid pointer value in place will cause a double-free when users call nft_ctx_clear_vars() first, then nft_ctx_free(). Moreover, nft_ctx_add_var() passes the pointer to mrealloc() and thus assumes it to be either NULL or valid.

Fixes 9edaa6a51eab4 ("src: add --define key=value")

Patch applied.