ia64/xen-unstable
changeset 9823:8db5ac82c20f
Fix command-line parsing in a few respects -- be more
generous about what we accept, avoid stack overflow, and
print the command line during boot (rather useful!).
This should fix the 'lapic' and 'nolapic' boot options.
Signed-off-by: Keir Fraser <keir@xensource.com>
generous about what we accept, avoid stack overflow, and
print the command line during boot (rather useful!).
This should fix the 'lapic' and 'nolapic' boot options.
Signed-off-by: Keir Fraser <keir@xensource.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Fri Apr 21 18:09:32 2006 +0100 (2006-04-21) |
parents | 2b37b17cca09 |
children | 1171e42b900f |
files | xen/arch/x86/setup.c xen/common/kernel.c |
line diff
1.1 --- a/xen/arch/x86/setup.c Fri Apr 21 18:06:06 2006 +0100 1.2 +++ b/xen/arch/x86/setup.c Fri Apr 21 18:09:32 2006 +0100 1.3 @@ -194,7 +194,7 @@ static void percpu_free_unused_areas(voi 1.4 1.5 void __init __start_xen(multiboot_info_t *mbi) 1.6 { 1.7 - char *cmdline; 1.8 + char __cmdline[] = "", *cmdline = __cmdline; 1.9 struct domain *idle_domain; 1.10 unsigned long _initrd_start = 0, _initrd_len = 0; 1.11 unsigned int initrdidx = 1; 1.12 @@ -210,7 +210,8 @@ void __init __start_xen(multiboot_info_t 1.13 1.14 /* Parse the command-line options. */ 1.15 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) ) 1.16 - cmdline_parse(__va(mbi->cmdline)); 1.17 + cmdline = __va(mbi->cmdline); 1.18 + cmdline_parse(cmdline); 1.19 1.20 set_current((struct vcpu *)0xfffff000); /* debug sanity */ 1.21 set_processor_id(0); /* needed early, for smp_processor_id() */ 1.22 @@ -228,6 +229,8 @@ void __init __start_xen(multiboot_info_t 1.23 1.24 init_console(); 1.25 1.26 + printf("Command line: %s\n", cmdline); 1.27 + 1.28 /* Check that we have at least one Multiboot module. */ 1.29 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) ) 1.30 {
2.1 --- a/xen/common/kernel.c Fri Apr 21 18:06:06 2006 +0100 2.2 +++ b/xen/common/kernel.c Fri Apr 21 18:09:32 2006 +0100 2.3 @@ -43,13 +43,19 @@ void cmdline_parse(char *cmdline) 2.4 /* Grab the next whitespace-delimited option. */ 2.5 q = opt; 2.6 while ( (*p != ' ') && (*p != '\0') ) 2.7 - *q++ = *p++; 2.8 + { 2.9 + if ( (q-opt) < (sizeof(opt)-1) ) /* avoid overflow */ 2.10 + *q++ = *p; 2.11 + p++; 2.12 + } 2.13 *q = '\0'; 2.14 2.15 /* Search for value part of a key=value option. */ 2.16 optval = strchr(opt, '='); 2.17 if ( optval != NULL ) 2.18 - *optval++ = '\0'; 2.19 + *optval++ = '\0'; /* nul-terminate the option value */ 2.20 + else 2.21 + optval = q; /* default option value is empty string */ 2.22 2.23 for ( param = &__setup_start; param <= &__setup_end; param++ ) 2.24 { 2.25 @@ -59,23 +65,18 @@ void cmdline_parse(char *cmdline) 2.26 switch ( param->type ) 2.27 { 2.28 case OPT_STR: 2.29 - if ( optval != NULL ) 2.30 - { 2.31 - strncpy(param->var, optval, param->len); 2.32 - ((char *)param->var)[param->len-1] = '\0'; 2.33 - } 2.34 + strncpy(param->var, optval, param->len); 2.35 + ((char *)param->var)[param->len-1] = '\0'; 2.36 break; 2.37 case OPT_UINT: 2.38 - if ( optval != NULL ) 2.39 - *(unsigned int *)param->var = 2.40 - simple_strtol(optval, (char **)&optval, 0); 2.41 + *(unsigned int *)param->var = 2.42 + simple_strtol(optval, (char **)&optval, 0); 2.43 break; 2.44 case OPT_BOOL: 2.45 *(int *)param->var = 1; 2.46 break; 2.47 case OPT_CUSTOM: 2.48 - if ( optval != NULL ) 2.49 - ((void (*)(char *))param->var)(optval); 2.50 + ((void (*)(char *))param->var)(optval); 2.51 break; 2.52 } 2.53 }