debuggers.hg

changeset 20845:fd8707f8698d

libxenlight: add fuse around generic_device_add related to invalid kinds

prevent segfault in case the backend or frontend kinds have
not been set to a correct kind value (or not initilized).

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 14 09:41:34 2010 +0000 (2010-01-14)
parents 94442ca0423d
children 7a412f9f6aae
files tools/libxl/libxl_device.c tools/libxl/libxl_internal.h
line diff
     1.1 --- a/tools/libxl/libxl_device.c	Thu Jan 14 09:40:55 2010 +0000
     1.2 +++ b/tools/libxl/libxl_device.c	Thu Jan 14 09:41:34 2010 +0000
     1.3 @@ -26,7 +26,7 @@
     1.4  #include "libxl.h"
     1.5  #include "libxl_internal.h"
     1.6  
     1.7 -const char *string_of_kinds[] = {
     1.8 +static const char *string_of_kinds[] = {
     1.9      [DEVICE_VIF] = "vif",
    1.10      [DEVICE_VBD] = "vbd",
    1.11      [DEVICE_TAP] = "tap",
    1.12 @@ -45,6 +45,9 @@ int libxl_device_generic_add(struct libx
    1.13      struct xs_permissions backend_perms[2];
    1.14      struct xs_permissions hotplug_perms[1];
    1.15  
    1.16 +    if (!is_valid_device_kind(device->backend_kind) || !is_valid_device_kind(device->kind))
    1.17 +        return ERROR_INVAL;
    1.18 +
    1.19      dom_path_backend = libxl_xs_get_dompath(ctx, device->backend_domid);
    1.20      dom_path = libxl_xs_get_dompath(ctx, device->domid);
    1.21  
     2.1 --- a/tools/libxl/libxl_internal.h	Thu Jan 14 09:40:55 2010 +0000
     2.2 +++ b/tools/libxl/libxl_internal.h	Thu Jan 14 09:41:34 2010 +0000
     2.3 @@ -68,7 +68,7 @@ typedef enum {
     2.4      DEVICE_CONSOLE,
     2.5  } libxl_device_kinds;
     2.6  
     2.7 -extern const char *string_of_kinds[];
     2.8 +#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
     2.9  
    2.10  typedef struct {
    2.11      uint32_t backend_devid;