Skip to contentSkip to conversation

libxenlight: fix segfault when domid_to_name returns NULL

PATCH New Eamon Walsh 1 participant 1 message Mar 12, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxenlight: fix segfault when domid_to_name returns NULL

The function libxl_domid_to_name() can return NULL if the path /local/domain/%d/name does not exist. This causes a segfault if the NULL name is later passed as a value to libxl_xs_writev(). I'm hitting this making a call to libxl_device_vfb_add() from my graphical switcher application.

This patch modifies xs_writev() and libxl_xs_writev() to skip NULL values.

---

Alternative approaches would be to either not return NULL from libxl_domid_to_name(), or not to include "name" in the list of key/values within libxl_device_vfb_add() and friends.

tools/libxl/libxl_xshelp.c +3 -3
diff -r 4152a3ce90a7 tools/libxl/libxl_xshelp.c
@@ -33,11 +33,11 @@
 
     for (i = 0; kvs[i] != NULL; i += 2) {
         asprintf(&path, "%s/%s", dir, kvs[i]);
-        if (path) {
+        if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
             xs_write(xsh, t, path, kvs[i + 1], length);
-            free(path);
         }
+        free(path);
     }
     return 0;
 }
@@ -74,7 +74,7 @@
 
     for (i = 0; kvs[i] != NULL; i += 2) {
         path = libxl_sprintf(ctx, "%s/%s", dir, kvs[i]);
-        if (path) {
+        if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
             xs_write(ctx->xsh, t, path, kvs[i + 1], length);
         }
Signature · 2 lines
Eamon Walsh 
National Security Agency