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