a5bd9f6
From acfa4335f7ed7310e7ee2da1f68443785f7f7913 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
a5bd9f6
Date: Mon, 10 Dec 2012 16:23:16 +0100
a5bd9f6
Subject: [PATCH 063/364] 	* grub-core/kern/ieee1275/init.c
a5bd9f6
 (grub_machine_get_bootlocation): Use 	dynamic allocation for the bootpath
a5bd9f6
 buffer.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                      |  5 +++++
a5bd9f6
 grub-core/kern/ieee1275/init.c | 21 +++++++++++++++++----
a5bd9f6
 2 files changed, 22 insertions(+), 4 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index ce822ee..8bd581e 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,8 @@
a5bd9f6
+2012-12-10  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
a5bd9f6
+
a5bd9f6
+	* grub-core/kern/ieee1275/init.c (grub_machine_get_bootlocation): Use
a5bd9f6
+	dynamic allocation for the bootpath buffer.
a5bd9f6
+
a5bd9f6
 2012-12-10  Dr. Tilmann Bubeck <t.bubeck@reinform.de>
a5bd9f6
 
a5bd9f6
 	* grub-core/gfxmenu/view.c (init_terminal): Avoid making terminal
a5bd9f6
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
a5bd9f6
index 7d03a8a..14dcdf0 100644
a5bd9f6
--- a/grub-core/kern/ieee1275/init.c
a5bd9f6
+++ b/grub-core/kern/ieee1275/init.c
a5bd9f6
@@ -82,18 +82,30 @@ void (*grub_ieee1275_net_config) (const char *dev,
a5bd9f6
 void
a5bd9f6
 grub_machine_get_bootlocation (char **device, char **path)
a5bd9f6
 {
a5bd9f6
-  char bootpath[64]; /* XXX check length */
a5bd9f6
+  char *bootpath;
a5bd9f6
+  grub_ssize_t bootpath_size;
a5bd9f6
   char *filename;
a5bd9f6
   char *type;
a5bd9f6
-   
a5bd9f6
-  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
a5bd9f6
-				  sizeof (bootpath), 0))
a5bd9f6
+
a5bd9f6
+  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
a5bd9f6
+					 &bootpath_size)
a5bd9f6
+      || bootpath_size <= 0)
a5bd9f6
     {
a5bd9f6
       /* Should never happen.  */
a5bd9f6
       grub_printf ("/chosen/bootpath property missing!\n");
a5bd9f6
       return;
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
+  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
a5bd9f6
+  if (! bootpath)
a5bd9f6
+    {
a5bd9f6
+      grub_print_error ();
a5bd9f6
+      return;
a5bd9f6
+    }
a5bd9f6
+  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
a5bd9f6
+                              (grub_size_t) bootpath_size + 1, 0);
a5bd9f6
+  bootpath[bootpath_size] = '\0';
a5bd9f6
+
a5bd9f6
   /* Transform an OF device path to a GRUB path.  */
a5bd9f6
 
a5bd9f6
   type = grub_ieee1275_get_device_type (bootpath);
a5bd9f6
@@ -132,6 +144,7 @@ grub_machine_get_bootlocation (char **device, char **path)
a5bd9f6
 	  *path = filename;
a5bd9f6
 	}
a5bd9f6
     }
a5bd9f6
+  grub_free (bootpath);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 /* Claim some available memory in the first /memory node. */
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6