[syslinux:elflink] ldlinux: Pass entire cmdline to execute()

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Wed Apr 27 14:30:39 PDT 2011


Commit-ID:  27a4a7785bef251ab58cf99ad73e59ee838ff30b
Gitweb:     http://syslinux.zytor.com/commit/27a4a7785bef251ab58cf99ad73e59ee838ff30b
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Fri, 8 Apr 2011 13:15:43 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Sat, 16 Apr 2011 14:49:26 +0100

ldlinux: Pass entire cmdline to execute()

We need to pass the entire cmdline to execute(), not just the kernel
name. execute() does all the required processing of cmdline arguments
and passes them to the loader in the correct format, e.g. for COM32
modules the cmdline arguments need to be passed in the traditional
char *argv[] way.

So stop using strtok() which modifies its first argument and means we
therefore lose the cmdline after the kernel name.

Previously, the "argc" and "argv" arguments that are passed to a
module's main() function contained bogus values.

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


---
 com32/elflink/ldlinux/ldlinux.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index 36eaded..839a28a 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -22,8 +22,7 @@ static void load_kernel(const char *kernel)
 {
 	struct menu_entry *me;
 	enum kernel_type type;
-	const char *cmdline;
-	char *kernel_name;
+	const char *cmdline, *p;
 	int len;
 
 	/* Virtual kernel? */
@@ -38,23 +37,25 @@ static void load_kernel(const char *kernel)
 	if (!allowimplicit)
 		goto bad_implicit;
 
-	kernel_name = strtok((char *)kernel, COMMAND_DELIM);
-	len = strlen(kernel_name);
+	/* Find the end of the command */
+	while (*p && !my_isspace(*p))
+		p++;
 
-	if (!strcmp(kernel_name + len - 4, ".c32")) {
+	len = p - kernel;
+	if (!strncmp(kernel + len - 4, ".c32", 4)) {
 		type = KT_COM32;
-	} else if (!strcmp(kernel_name + len - 2, ".0")) {
+	} else if (!strncmp(kernel + len - 2, ".0", 2)) {
 		type = KT_PXE;
-	} else if (!strcmp(kernel_name + len - 3, ".bs")) {
+	} else if (!strncmp(kernel + len - 3, ".bs", 3)) {
 		type = KT_BOOT;
-	} else if (!strcmp(kernel_name + len - 4, ".img")) {
+	} else if (!strncmp(kernel + len - 4, ".img", 4)) {
 		type = KT_FDIMAGE;
-	} else if (!strcmp(kernel_name + len - 4, ".bin")) {
+	} else if (!strncmp(kernel + len - 4, ".bin", 4)) {
 		type = KT_BOOT;
-	} else if (!strcmp(kernel_name + len - 4, ".bss")) {
+	} else if (!strncmp(kernel + len - 4, ".bss", 4)) {
 		type = KT_BSS;
-	} else if (!strcmp(kernel_name + len - 4, ".com")
-	       || !strcmp(kernel_name + len - 4, ".cbt")) {
+	} else if (!strncmp(kernel + len - 4, ".com", 4) ||
+		   !strncmp(kernel + len - 4, ".cbt", 4)) {
 		type = KT_COMBOOT;
 	}
 	/* use KT_KERNEL as default */



More information about the Syslinux-commits mailing list