From fd0b2e7a242568f5b11f8a22ce0c3f639e6bbbfc Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Fri, 8 Jul 2022 16:49:36 +0200 Subject: Fix: libfstree: double free in error path If fstree_mknode fails, because the parent link count would overflow, the function fails and cleans up behind it. The problem arises because the function does this check *after* inserting the node in the parent node, so it is later free'd again, when destroying the rest of the tree. This patch moves the insertion after the check to mitigate the problem. Reported-by: Marvin Renich Signed-off-by: David Oberhollenzer --- lib/fstree/mknode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c index 7d6e315..11026f6 100644 --- a/lib/fstree/mknode.c +++ b/lib/fstree/mknode.c @@ -88,14 +88,13 @@ tree_node_t *fstree_mknode(tree_node_t *parent, const char *name, } if (parent != NULL) { - fstree_insert_sorted(parent, n); - if (parent->link_count == 0x0FFFF) { free(n); errno = EMLINK; return NULL; } + fstree_insert_sorted(parent, n); parent->link_count++; } -- cgit v1.2.3