From 9ba4d7a122dfc4e3e03d0112ad03115b3065a238 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 24 Jun 2021 14:47:41 +0200 Subject: libfstree: guard against link count and inode number overflow If the hard link counter or the inode number counter overflow the maximum representable value (for SquashFS 16 bit and 32 bit respecitively), abort with an error message. Signed-off-by: David Oberhollenzer --- lib/fstree/mknode.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/fstree/mknode.c') diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c index 4353b74..f836c67 100644 --- a/lib/fstree/mknode.c +++ b/lib/fstree/mknode.c @@ -70,10 +70,19 @@ tree_node_t *fstree_mknode(tree_node_t *parent, const char *name, case S_IFDIR: n->link_count = 2; break; + default: + break; } - if (parent != NULL) - parent->link_count += 1; + if (parent != NULL) { + if (parent->link_count == 0x0FFFF) { + free(n); + errno = EMLINK; + return NULL; + } + + parent->link_count++; + } return n; } -- cgit v1.2.3