ia64/xen-unstable

changeset 8541:0a69deed5e1f

Proactively check for NULL strings passed into xc_linux_build. Either DTRT
or return error if detected. A NULL cmdline, for example, would currently
generate a segfault.

Signed-off-by: Ben Thomas <bjthomas3@gmail.com>
author emellor@leeni.uk.xensource.com
date Tue Jan 10 14:37:25 2006 +0000 (2006-01-10)
parents fbee8d9fbaba
children bb62be2a5080
files tools/libxc/xc_linux_build.c
line diff
     1.1 --- a/tools/libxc/xc_linux_build.c	Tue Jan 10 14:33:00 2006 +0000
     1.2 +++ b/tools/libxc/xc_linux_build.c	Tue Jan 10 14:37:25 2006 +0000
     1.3 @@ -693,8 +693,11 @@ static int setup_guest(int xc_handle,
     1.4          start_info->mod_start    = vinitrd_start;
     1.5          start_info->mod_len      = initrd_len;
     1.6      }
     1.7 -    strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
     1.8 -    start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
     1.9 +    if (cmdline != NULL) {
    1.10 +        strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
    1.11 +        start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
    1.12 +    } else
    1.13 +        start_info->cmd_line[0] = '\0';
    1.14      munmap(start_info, PAGE_SIZE);
    1.15  
    1.16      /* shared_info page starts its life empty. */
    1.17 @@ -755,7 +758,8 @@ int xc_linux_build(int xc_handle,
    1.18          goto error_out;
    1.19      }
    1.20  
    1.21 -    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
    1.22 +    if ( (image_name == NULL) ||
    1.23 +         ((image = xc_read_kernel_image(image_name, &image_size)) == NULL) )
    1.24          goto error_out;
    1.25  
    1.26      if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) )