Skip to contentSkip to conversation

libnftables: fix crash when freeing non-malloc'd address

PATCH In review Florian Westphal 2 participants 2 messages Jul 10, 2024 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 libnftables: fix crash when freeing non-malloc'd address

dirname may return static pointer:
munmap_chunk(): invalid pointer
20508 Aborted nft -f test

Fixes 6ef04f99382c ("libnftables: search for default include path last")
---
 src/libnftables.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/libnftables.c +3 -3
index af4734c05004..586f8fdede76 100644
@@ -789,12 +789,12 @@ static int nft_run_optimized_file(struct nft_ctx *nft, const char *filename)
 static int nft_ctx_add_basedir_include_path(struct nft_ctx *nft,
 					    const char *filename)
 {
-	const char *basedir = dirname(xstrdup(filename));
+	char *basedir = xstrdup(filename);
 	int ret;
 
-	ret = nft_ctx_add_include_path(nft, basedir);
+	ret = nft_ctx_add_include_path(nft, dirname(basedir));
 
-	free_const(basedir);
+	free(basedir);
 
 	return ret;
 }
Signature · 1 line
2.44.2
#1 lore raw
Quoted 3 lines · Florian Westphal

dirname may return static pointer:
munmap_chunk(): invalid pointer
20508 Aborted nft -f test

LGTM, thanks Florian