[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] xc_linux_build - proactively check for NULL string arguments


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: B Thomas <bjthomas3@xxxxxxxxx>
  • Date: Mon, 9 Jan 2006 20:07:23 -0500
  • Delivery-date: Tue, 10 Jan 2006 01:14:02 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Djk8OAD1JyDnncuu9pPfq1wAfzyAIxxYbJ+vSKoeUeDraegxTPJr46/sEtwCvssBv22lPCHHWIfSuPe6rznNRGEdfFcW+3MzNvzOULn+B94d/bFV0zAPU2KKGYsCTfn0hryXIx09KSwYHoSGyZYIjKJSOe+FqAftQ/RooM+LAkk=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

[Forgot to say "please", errr, tag this as [PATCH]...oops]

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

Signed-off-by:  Ben Thomas   bjthomas3@xxxxxxxxx



diff -r 5b30599761b3 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Mon Jan  2 10:35:29 2006
+++ b/tools/libxc/xc_linux_build.c      Wed Jan  4 19:31:22 2006
@@ -689,8 +689,11 @@
         start_info->mod_start    = vinitrd_start;
         start_info->mod_len      = initrd_len;
     }
-    strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
-    start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
+    if (cmdline != NULL) {
+        strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
+        start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
+    } else
+        start_info->cmd_line[0] = '\0';
     munmap(start_info, PAGE_SIZE);

     /* shared_info page starts its life empty. */
@@ -751,7 +754,8 @@
         goto error_out;
     }

-    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
+    if ( (image_name == NULL) ||
+         ((image = xc_read_kernel_image(image_name, &image_size)) == NULL ) )
         goto error_out;

     if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) )

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.