grub-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]