[syslinux:elflink] ldlinux: Parse kernel type for labels

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon Mar 26 15:36:02 PDT 2012


Commit-ID:  b0a737c5cdbd7de3790bc5cf9a0e4b21dd1aed56
Gitweb:     http://www.syslinux.org/commit/b0a737c5cdbd7de3790bc5cf9a0e4b21dd1aed56
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 9 Feb 2012 10:15:38 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Tue, 13 Mar 2012 10:22:03 +0000

ldlinux: Parse kernel type for labels

We need to parse the kernel type for labels aswell as things entered
on the cmdline, instead of always passing KT_KERNEL or KT_NONE to
execute(). Move the logic into a new helper function.

This fixes a bug where an incorrect kernel type would be passed to
execute() if anything other than a linux kernel (such as a .bin) was
specified in a LABEL's KERNEL argument, which resulted in the file not
being executed.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/elflink/ldlinux/ldlinux.c |   66 ++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 28 deletions(-)

diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index 5360417..dcde542 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -11,43 +11,19 @@
 
 #include <sys/module.h>
 
-/*
- * Attempt to load a kernel after deciding what type of image it is.
- *
- * We only return from this function if something went wrong loading
- * the the kernel. If we return the caller should call enter_cmdline()
- * so that the user can help us out.
- */
-static void load_kernel(const char *kernel)
+static enum kernel_type parse_kernel_type(char *kernel)
 {
-	struct menu_entry *me;
 	enum kernel_type type;
-	const char *cmdline, *p;
+	const char *p;
 	int len;
 
-	/* Virtual kernel? */
-	me = find_label(kernel);
-	if (me) {
-		enum kernel_type type = KT_KERNEL;
-
-		/* cmdline contains type specifier */
-		if (me->cmdline[0] == '.')
-			type = KT_NONE;
-
-		execute(me->cmdline, type);
-		/* We shouldn't return */
-		goto bad_kernel;
-	}
-
-	if (!allowimplicit)
-		goto bad_implicit;
-
-	p = kernel;
 	/* Find the end of the command */
+	p = kernel;
 	while (*p && !my_isspace(*p))
 		p++;
 
 	len = p - kernel;
+
 	if (!strncmp(kernel + len - 4, ".c32", 4)) {
 		type = KT_COM32;
 	} else if (!strncmp(kernel + len - 2, ".0", 2)) {
@@ -68,6 +44,40 @@ static void load_kernel(const char *kernel)
 	else
 		type = KT_KERNEL;
 
+	return type;
+}
+
+/*
+ * Attempt to load a kernel after deciding what type of image it is.
+ *
+ * We only return from this function if something went wrong loading
+ * the the kernel. If we return the caller should call enter_cmdline()
+ * so that the user can help us out.
+ */
+static void load_kernel(const char *kernel)
+{
+	struct menu_entry *me;
+	enum kernel_type type;
+	const char *cmdline;
+
+	/* Virtual kernel? */
+	me = find_label(kernel);
+	if (me) {
+		type = parse_kernel_type(me->cmdline);
+
+		/* cmdline contains type specifier */
+		if (me->cmdline[0] == '.')
+			type = KT_NONE;
+
+		execute(me->cmdline, type);
+		/* We shouldn't return */
+		goto bad_kernel;
+	}
+
+	if (!allowimplicit)
+		goto bad_implicit;
+
+	type = parse_kernel_type(kernel);
 	execute(kernel, type);
 
 bad_implicit:


More information about the Syslinux-commits mailing list