From: B Thomas Subject: xc_linux_build - proactively check for NULL string arguments Date: Wed, 4 Jan 2006 19:33:53 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1241256995==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1241256995== Content-Type: multipart/alternative; boundary="----=_Part_48657_32647498.1136421233349" ------=_Part_48657_32647498.1136421233349 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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@gmail.com 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 =3D vinitrd_start; start_info->mod_len =3D initrd_len; } - strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE); - start_info->cmd_line[MAX_GUEST_CMDLINE-1] =3D '\0'; + if (cmdline !=3D NULL) { + strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE); + start_info->cmd_line[MAX_GUEST_CMDLINE-1] =3D '\0'; + } else + start_info->cmd_line[0] =3D '\0'; munmap(start_info, PAGE_SIZE); /* shared_info page starts its life empty. */ @@ -751,7 +754,8 @@ goto error_out; } - if ( (image =3D xc_read_kernel_image(image_name, &image_size)) =3D=3D = NULL ) + if ( (image_name =3D=3D NULL) || + ((image =3D xc_read_kernel_image(image_name, &image_size)) =3D=3D= NULL ) ) goto error_out; if ( (ramdisk_name !=3D NULL) && (strlen(ramdisk_name) !=3D 0) ) ------=_Part_48657_32647498.1136421233349 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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@gmail.com



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&= nbsp;     Wed Jan  4 19:31:22 2006
@@ -689,8 +689,11 @@
        = ; start_info->mod_start    =3D vinitrd_start;
 &n= bsp;       start_info->mod_len  =     =3D initrd_len;
     }
- =    strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CM= DLINE);
-    start_info->cmd_line[MAX_GUEST_CMDLINE-1] =3D '\= 0';
+    if (cmdline !=3D NULL) {
+   &= nbsp;    strncpy((char *)start_info->cmd_line, cmdline, M= AX_GUEST_CMDLINE);
+        start_inf= o->cmd_line[MAX_GUEST_CMDLINE-1] =3D '\0';
+    } else
+      &nbs= p; start_info->cmd_line[0] =3D '\0';
     munmap(= start_info, PAGE_SIZE);

     /* shared_info page= starts its life empty. */
@@ -751,7 +754,8 @@
   &nbs= p;     goto error_out;
     }
-    if ( (image =3D xc_read_kernel_image(image_name, &a= mp;image_size)) =3D=3D NULL )
+    if ( (image_name =3D= =3D NULL) ||
+         ((image = =3D xc_read_kernel_image(image_name, &image_size)) =3D=3D NULL ) )
&= nbsp;        goto error_out;

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

------=_Part_48657_32647498.1136421233349-- --===============1241256995== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1241256995==--