Skip to contentSkip to conversation

xc_linux_build - proactively check for NULL string arguments

PATCH In review B Thomas 2 participants 3 messages Jan 5, 2006 – Jan 10, 2006

lore
Share & tools
lore

B Thomas

author
#0 lore raw

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.

tools/libxc/xc_linux_build.c Wed Jan 4 19:31:22 2006 renamed from tools/libxc/xc_linux_build.c Mon Jan 2 10:35:29 2006 +7 -3
diff -r 5b30599761b3 tools/libxc/xc_linux_build.c
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

author
#1 lore raw

PATCH 1/1 xc_linux_build - proactively check for NULL string arguments

[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.

tools/libxc/xc_linux_build.c Wed Jan 4 19:31:22 2006 renamed from tools/libxc/xc_linux_build.c Mon Jan 2 10:35:29 2006 +7 -3
diff -r 5b30599761b3 tools/libxc/xc_linux_build.c
@@ -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
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 7 lines · B Thomas

[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.

Sorry, didn't mean to miss you -- I've just been a bit busy -- it's applied now. (In fact, Keir applied it at the same time, so it's in the tree twice ;-)

Ewan.