[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V2 4/9] fs/ntfs: Fix memory leak in grub_ntfs_read_symlink
From: |
t . feng |
Subject: |
[PATCH V2 4/9] fs/ntfs: Fix memory leak in grub_ntfs_read_symlink |
Date: |
Tue, 29 Nov 2022 17:14:10 +0800 |
Fix memory leaks in grub_ntfs_read_symlink.
Fixes: 5773fb641(Support NTFS reparse points.)
Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
grub-core/fs/ntfs.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c
index 3511e4e2c..bbdbe24ad 100644
--- a/grub-core/fs/ntfs.c
+++ b/grub-core/fs/ntfs.c
@@ -654,7 +654,7 @@ grub_ntfs_read_symlink (grub_fshelp_node_t node)
struct grub_ntfs_file *mft;
struct symlink_descriptor symdesc;
grub_err_t err;
- grub_uint8_t *buf16;
+ grub_uint8_t *buf16 = NULL;
char *buf, *end;
grub_size_t len;
grub_uint8_t *pa;
@@ -667,20 +667,20 @@ grub_ntfs_read_symlink (grub_fshelp_node_t node)
return NULL;
if (read_mft (mft->data, mft->buf, mft->ino))
- return NULL;
+ goto fail;
pa = locate_attr (&mft->attr, mft, GRUB_NTFS_AT_SYMLINK);
if (pa == NULL)
{
grub_error (GRUB_ERR_BAD_FS, "no $SYMLINK in MFT 0x%llx",
(unsigned long long) mft->ino);
- return NULL;
+ goto fail;
}
err = read_attr (&mft->attr, (grub_uint8_t *) &symdesc, 0,
sizeof (struct symlink_descriptor), 1, 0, 0);
if (err)
- return NULL;
+ goto fail;
switch (grub_cpu_to_le32 (symdesc.type))
{
@@ -697,23 +697,22 @@ grub_ntfs_read_symlink (grub_fshelp_node_t node)
default:
grub_error (GRUB_ERR_BAD_FS, "symlink type invalid (%x)",
grub_cpu_to_le32 (symdesc.type));
- return NULL;
+ goto fail;
}
buf16 = grub_malloc (len);
if (!buf16)
- return NULL;
+ goto fail;
err = read_attr (&mft->attr, buf16, off, len, 1, 0, 0);
if (err)
- return NULL;
+ goto fail;
buf = get_utf8 (buf16, len / 2);
if (!buf)
- {
- grub_free (buf16);
- return NULL;
- }
+ goto fail;
+
+ grub_free (mft->buf);
grub_free (buf16);
for (end = buf; *end; end++)
@@ -728,6 +727,11 @@ grub_ntfs_read_symlink (grub_fshelp_node_t node)
end -= 6;
}
return buf;
+
+ fail:
+ grub_free (mft->buf);
+ grub_free (buf16);
+ return NULL;
}
static int
--
2.27.0
- [PATCH V2 0/9] fix memory leaks in fs module, t . feng, 2022/11/29
- [PATCH V2 3/9] fs/minix: Fix memory leak in grub_minix_lookup_symlink, t . feng, 2022/11/29
- [PATCH V2 7/9] fs/iso9660: Fix memory leak in grub_iso9660_susp_iterate, t . feng, 2022/11/29
- [PATCH V2 2/9] fs/btrfs: Fix memory leak in find_path, t . feng, 2022/11/29
- [PATCH V2 8/9] fs/squash4: Fix memeory leak in grub_squash_iterate_dir, t . feng, 2022/11/29
- [PATCH V2 6/9] fs/hfsplus: Fix memory leak in grub_hfsplus_btree_search, t . feng, 2022/11/29
- [PATCH V2 9/9] fs/xfs: Fix memory leaks in xfs, t . feng, 2022/11/29
- [PATCH V2 5/9] fs/bfs: Fix memory leak in read_bfs_file, t . feng, 2022/11/29
- [PATCH V2 1/9] fs/affs:Fix memory leaks in grub_affs_create_node, t . feng, 2022/11/29
- [PATCH V2 4/9] fs/ntfs: Fix memory leak in grub_ntfs_read_symlink,
t . feng <=
- Re: [PATCH V2 0/9] fix memory leaks in fs module, Daniel Kiper, 2022/11/29