ldlinux: Parse kernel type for labels
authorMatt Fleming <matt.fleming@intel.com>
Thu, 9 Feb 2012 10:15:38 +0000 (10:15 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Tue, 13 Mar 2012 10:22:03 +0000 (10:22 +0000)
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@intel.com>
com32/elflink/ldlinux/ldlinux.c

index 5360417..dcde542 100644 (file)
 
 #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: