dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0425-kern-parser-Refactor-grub_parser_split_cmdline-clean.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b1bcb2
From: Chris Coulson <chris.coulson@canonical.com>
b1bcb2
Date: Wed, 6 Jan 2021 13:54:26 +0000
b1bcb2
Subject: [PATCH] kern/parser: Refactor grub_parser_split_cmdline() cleanup
b1bcb2
b1bcb2
Introduce a common function epilogue used for cleaning up on all
b1bcb2
return paths, which will simplify additional error handling to be
b1bcb2
introduced in a subsequent commit.
b1bcb2
b1bcb2
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
b1bcb2
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b1bcb2
---
b1bcb2
 grub-core/kern/parser.c | 35 ++++++++++++++++++++---------------
b1bcb2
 1 file changed, 20 insertions(+), 15 deletions(-)
b1bcb2
b1bcb2
diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c
b1bcb2
index 6ef90c82938..16879f072fe 100644
b1bcb2
--- a/grub-core/kern/parser.c
b1bcb2
+++ b/grub-core/kern/parser.c
b1bcb2
@@ -221,19 +221,13 @@ grub_parser_split_cmdline (const char *cmdline,
b1bcb2
 
b1bcb2
 	  if (process_char (*rp, buffer, &bp, varname, &vp, state, argc,
b1bcb2
 			    &newstate) != GRUB_ERR_NONE)
b1bcb2
-	    {
b1bcb2
-	      if (rd != cmdline)
b1bcb2
-		grub_free (rd);
b1bcb2
-	      return grub_errno;
b1bcb2
-	    }
b1bcb2
+	    goto fail;
b1bcb2
+
b1bcb2
 	  state = newstate;
b1bcb2
 	}
b1bcb2
     }
b1bcb2
   while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
b1bcb2
 
b1bcb2
-  if (rd != cmdline)
b1bcb2
-    grub_free (rd);
b1bcb2
-
b1bcb2
   /* A special case for when the last character was part of a
b1bcb2
      variable.  */
b1bcb2
   add_var (varname, &bp, &vp, state, GRUB_PARSER_STATE_TEXT);
b1bcb2
@@ -243,20 +237,20 @@ grub_parser_split_cmdline (const char *cmdline,
b1bcb2
 
b1bcb2
   /* If there are no args, then we're done. */
b1bcb2
   if (!*argc)
b1bcb2
-    return 0;
b1bcb2
+    {
b1bcb2
+      grub_errno = GRUB_ERR_NONE;
b1bcb2
+      goto out;
b1bcb2
+    }
b1bcb2
 
b1bcb2
   /* Reserve memory for the return values.  */
b1bcb2
   args = grub_malloc (bp - buffer);
b1bcb2
   if (!args)
b1bcb2
-    return grub_errno;
b1bcb2
+    goto fail;
b1bcb2
   grub_memcpy (args, buffer, bp - buffer);
b1bcb2
 
b1bcb2
   *argv = grub_calloc (*argc + 1, sizeof (char *));
b1bcb2
   if (!*argv)
b1bcb2
-    {
b1bcb2
-      grub_free (args);
b1bcb2
-      return grub_errno;
b1bcb2
-    }
b1bcb2
+    goto fail;
b1bcb2
 
b1bcb2
   /* The arguments are separated with 0's, setup argv so it points to
b1bcb2
      the right values.  */
b1bcb2
@@ -269,7 +263,18 @@ grub_parser_split_cmdline (const char *cmdline,
b1bcb2
       bp++;
b1bcb2
     }
b1bcb2
 
b1bcb2
-  return 0;
b1bcb2
+  grub_errno = GRUB_ERR_NONE;
b1bcb2
+
b1bcb2
+ out:
b1bcb2
+  if (rd != cmdline)
b1bcb2
+    grub_free (rd);
b1bcb2
+
b1bcb2
+  return grub_errno;
b1bcb2
+
b1bcb2
+ fail:
b1bcb2
+  grub_free (*argv);
b1bcb2
+  grub_free (args);
b1bcb2
+  goto out;
b1bcb2
 }
b1bcb2
 
b1bcb2
 /* Helper for grub_parser_execute.  */