]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
mtree: fix file descriptor leak in cleanup 2878/head
authorLoboQ1ng <xpess@qq.com>
Sun, 1 Mar 2026 19:53:47 +0000 (19:53 +0000)
committerLoboQ1ng <xpess@qq.com>
Sun, 1 Mar 2026 19:53:47 +0000 (19:53 +0000)
Close any dangling file descriptor in the mtree cleanup function to prevent FD exhaustion (CWE-775) when a read loop is aborted early.

libarchive/archive_read_support_format_mtree.c

index 10c07b05d965b5d785f9c7d66cff6decb494b9e9..4a5a49ca813635c7113a30595838a4487ebff473 100644 (file)
@@ -300,7 +300,12 @@ cleanup(struct archive_read *a)
        struct mtree_entry *p, *q;
 
        mtree = (struct mtree *)(a->format->data);
-
+       
+       /* Close any dangling file descriptor before freeing */
+    if (mtree->fd >= 0) {
+        close(mtree->fd);
+        mtree->fd = -1;
+    }
        p = mtree->entries;
        while (p != NULL) {
                q = p->next;