Blame SOURCES/0289-xnu-Fix-double-free-in-grub_xnu_devprop_add_property.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c294fc
From: Alexey Makhalov <amakhalov@vmware.com>
c294fc
Date: Wed, 8 Jul 2020 21:30:43 +0000
9723a8
Subject: [PATCH] xnu: Fix double free in grub_xnu_devprop_add_property()
c294fc
c294fc
grub_xnu_devprop_add_property() should not free utf8 and utf16 as it get
c294fc
allocated and freed in the caller.
c294fc
c294fc
Minor improvement: do prop fields initialization after memory allocations.
c294fc
c294fc
Fixes: CID 292442, CID 292457, CID 292460, CID 292466
c294fc
c294fc
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
c294fc
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
c294fc
Upstream-commit-id: 4d5e2d13519
c294fc
---
c294fc
 grub-core/loader/i386/xnu.c | 19 +++++++++----------
c294fc
 1 file changed, 9 insertions(+), 10 deletions(-)
c294fc
c294fc
diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c
c294fc
index ee0eaadc4ee..c760db30fc0 100644
c294fc
--- a/grub-core/loader/i386/xnu.c
c294fc
+++ b/grub-core/loader/i386/xnu.c
c294fc
@@ -262,20 +262,19 @@ grub_xnu_devprop_add_property (struct grub_xnu_devprop_device_descriptor *dev,
c294fc
   if (!prop)
c294fc
     return grub_errno;
c294fc
 
c294fc
+  prop->data = grub_malloc (datalen);
c294fc
+  if (!prop->data)
c294fc
+    {
c294fc
+      grub_free (prop);
c294fc
+      return grub_errno;
c294fc
+    }
c294fc
+  grub_memcpy (prop->data, data, datalen);
c294fc
+
c294fc
   prop->name = utf8;
c294fc
   prop->name16 = utf16;
c294fc
   prop->name16len = utf16len;
c294fc
-
c294fc
   prop->length = datalen;
c294fc
-  prop->data = grub_malloc (prop->length);
c294fc
-  if (!prop->data)
c294fc
-    {
c294fc
-      grub_free (prop->name);
c294fc
-      grub_free (prop->name16);
c294fc
-      grub_free (prop);
c294fc
-      return grub_errno;
c294fc
-    }
c294fc
-  grub_memcpy (prop->data, data, prop->length);
c294fc
+
c294fc
   grub_list_push (GRUB_AS_LIST_P (&dev->properties),
c294fc
 		  GRUB_AS_LIST (prop));
c294fc
   return GRUB_ERR_NONE;