From 36b96b6d2c1aa23a5fe2fdd07cf943c58707e4bf Mon Sep 17 00:00:00 2001
From: Roland McGrath <roland@gnu.org>
Date: Sat, 4 Jan 2003 21:30:10 +0000
Subject: 2003-01-04  Roland McGrath  <roland@frob.com>

	* boot_script.c (boot_script_parse_line): Copy the file name into
	malloc'd storage.
	(add_arg): New arg TEXTLEN.  Store malloc'd copy of TEXT.
	(boot_script_parse_line): Update callers.
---
 boot/boot_script.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

(limited to 'boot/boot_script.c')

diff --git a/boot/boot_script.c b/boot/boot_script.c
index cfc19c2b..6fd449b2 100644
--- a/boot/boot_script.c
+++ b/boot/boot_script.c
@@ -175,14 +175,14 @@ add_list (void *ptr, void ***ptr_list, int *alloc, int *index, int incr)
 /* Create an argument with TEXT, value type TYPE, and value VAL.
    Add the argument to the argument list of CMD.  */
 static struct arg *
-add_arg (struct cmd *cmd, char *text, int type, int val)
+add_arg (struct cmd *cmd, const char *text, int textlen, int type, int val)
 {
   struct arg *arg;
 
-  arg = boot_script_malloc (sizeof (struct arg));
+  arg = boot_script_malloc (sizeof (struct arg) + textlen);
   if (arg)
     {
-      arg->text = text;
+      arg->text = text == 0 ? 0 : memcpy (arg + 1, text, textlen);
       arg->type = type;
       arg->val = val;
       if (add_list (arg, (void ***) &cmd->args,
@@ -255,16 +255,16 @@ boot_script_parse_line (void *hook, char *cmdline)
   if (p == q)
       return 0;
 
-  *q = '\0';
+  *q++ = '\0';
 
   /* Allocate a command structure.  */
-  cmd = boot_script_malloc (sizeof (struct cmd));
+  cmd = boot_script_malloc (sizeof (struct cmd) + (q - p));
   if (! cmd)
     return BOOT_SCRIPT_NOMEM;
   memset (cmd, 0, sizeof (struct cmd));
   cmd->hook = hook;
-  cmd->path = p;
-  p = q + 1;
+  cmd->path = memcpy (cmd + 1, p, q - p);
+  p = q;
 
   for (arg = 0;;)
     {
@@ -408,7 +408,7 @@ boot_script_parse_line (void *hook, char *cmdline)
 		     associated with an argument.  */
 		  if (! arg && end_char == '}')
 		    {
-		      if (! add_arg (cmd, 0, type, val))
+		      if (! add_arg (cmd, 0, 0, type, val))
 			{
 			  error = BOOT_SCRIPT_NOMEM;
 			  goto bad;
@@ -437,7 +437,7 @@ boot_script_parse_line (void *hook, char *cmdline)
 	  *q = '\0';
 
 	  /* Add argument to list.  */
-	  arg = add_arg (cmd, p, VAL_NONE, 0);
+	  arg = add_arg (cmd, p, q + 1 - p, VAL_NONE, 0);
 	  if (! arg)
 	    {
 	      error = BOOT_SCRIPT_NOMEM;
-- 
cgit v1.2.3