]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
squashfs: Fix heap corruption in sqfs_search_dir()
authorRichard Weinberger <richard@nod.at>
Fri, 2 Aug 2024 20:05:09 +0000 (22:05 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 15 Aug 2024 22:14:36 +0000 (16:14 -0600)
res needs to be large enough to store both strings rem and target,
plus the path separator and the terminator.
Currently the space for the path separator is not accounted, so
the heap is corrupted by one byte.

Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
fs/squashfs/sqfs.c

index af7ff80a7bdfe9dcc75462eab65a5a70dc717b04..b9314019b1bcf4956a4b73e50f4e7350ca4c8cf8 100644 (file)
@@ -567,8 +567,11 @@ static int sqfs_search_dir(struct squashfs_dir_stream *dirs, char **token_list,
                                ret = -ENOMEM;
                                goto out;
                        }
-                       /* Concatenate remaining tokens and symlink's target */
-                       res = malloc(strlen(rem) + strlen(target) + 1);
+                       /*
+                        * Concatenate remaining tokens and symlink's target.
+                        * Allocate enough space for rem, target, '/' and '\0'.
+                        */
+                       res = malloc(strlen(rem) + strlen(target) + 2);
                        if (!res) {
                                ret = -ENOMEM;
                                goto out;