debuggers.hg

changeset 22286:38ad3633ecaf

xl: audit allocation of strings within libxl_device_*

* Remove string literals from init_*_info.
* Free any existing string values before overwriting during device
option parsing.
* Free libxl_device_console after use.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Wed Oct 13 12:01:30 2010 +0100 (2010-10-13)
parents 606b0eb2caa7
children 3a5755249361
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Wed Oct 13 11:54:04 2010 +0100
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Wed Oct 13 12:01:30 2010 +0100
     1.3 @@ -432,15 +432,18 @@ static void init_net2_info(libxl_device_
     1.4      net2_info->back_trusted = 1;
     1.5      net2_info->filter_mac = 1;
     1.6      net2_info->max_bypasses = 5;
     1.7 -    net2_info->bridge = "xenbr0";
     1.8 +    net2_info->bridge = strdup("xenbr0");
     1.9  }
    1.10  
    1.11  static void init_vfb_info(libxl_device_vfb *vfb, int dev_num)
    1.12  {
    1.13      memset(vfb, 0x00, sizeof(libxl_device_vfb));
    1.14      vfb->devid = dev_num;
    1.15 +    vfb->display = NULL;
    1.16 +    vfb->xauthority = NULL;
    1.17      vfb->vnc = 1;
    1.18 -    vfb->vnclisten = "127.0.0.1";
    1.19 +    vfb->vncpasswd = NULL;
    1.20 +    vfb->vnclisten = strdup("127.0.0.1");
    1.21      vfb->vncdisplay = 0;
    1.22      vfb->vncunused = 1;
    1.23      vfb->keymap = NULL;
    1.24 @@ -459,7 +462,7 @@ static void init_console_info(libxl_devi
    1.25      memset(console, 0x00, sizeof(libxl_device_console));
    1.26      console->devid = dev_num;
    1.27      console->consback = LIBXL_CONSBACK_XENCONSOLED;
    1.28 -    console->output = "pty";
    1.29 +    console->output = strdup("pty");
    1.30      if (state)
    1.31          console->build_state = state;
    1.32  }
    1.33 @@ -935,8 +938,10 @@ static void parse_config_data(const char
    1.34                  } else if (!strcmp(p, "ip")) {
    1.35                      inet_pton(AF_INET, p2 + 1, &nic->ip);
    1.36                  } else if (!strcmp(p, "script")) {
    1.37 +                    free(nic->script);
    1.38                      nic->script = strdup(p2 + 1);
    1.39                  } else if (!strcmp(p, "vifname")) {
    1.40 +                    free(nic->ifname);
    1.41                      nic->ifname = strdup(p2 + 1);
    1.42                  } else if (!strcmp(p, "backend")) {
    1.43                      if(libxl_name_to_domid(&ctx, (p2 + 1), &(nic->backend_domid))) {
    1.44 @@ -987,6 +992,7 @@ skip:
    1.45                  } else if (!strcmp("back_trusted", p)) {
    1.46                      net2->back_trusted = (*val == '1');
    1.47                  } else if (!strcmp("bridge", p)) {
    1.48 +                    free(net2->bridge);
    1.49                      net2->bridge = strdup(val);
    1.50                  } else if (!strcmp("filter_mac", p)) {
    1.51                      net2->filter_mac = (*val == '1');
    1.52 @@ -1035,22 +1041,27 @@ skip:
    1.53                  if (!strcmp(p, "vnc")) {
    1.54                      vfb->vnc = atoi(p2 + 1);
    1.55                  } else if (!strcmp(p, "vnclisten")) {
    1.56 +                    free(vfb->vnclisten);
    1.57                      vfb->vnclisten = strdup(p2 + 1);
    1.58                  } else if (!strcmp(p, "vncpasswd")) {
    1.59 +                    free(vfb->vncpasswd);
    1.60                      vfb->vncpasswd = strdup(p2 + 1);
    1.61                  } else if (!strcmp(p, "vncdisplay")) {
    1.62                      vfb->vncdisplay = atoi(p2 + 1);
    1.63                  } else if (!strcmp(p, "vncunused")) {
    1.64                      vfb->vncunused = atoi(p2 + 1);
    1.65                  } else if (!strcmp(p, "keymap")) {
    1.66 +                    free(vfb->keymap);
    1.67                      vfb->keymap = strdup(p2 + 1);
    1.68                  } else if (!strcmp(p, "sdl")) {
    1.69                      vfb->sdl = atoi(p2 + 1);
    1.70                  } else if (!strcmp(p, "opengl")) {
    1.71                      vfb->opengl = atoi(p2 + 1);
    1.72                  } else if (!strcmp(p, "display")) {
    1.73 +                    free(vfb->display);
    1.74                      vfb->display = strdup(p2 + 1);
    1.75                  } else if (!strcmp(p, "xauthority")) {
    1.76 +                    free(vfb->xauthority);
    1.77                      vfb->xauthority = strdup(p2 + 1);
    1.78                  }
    1.79              } while ((p = strtok(NULL, ",")) != NULL);
    1.80 @@ -1412,7 +1423,6 @@ static int create_domain(struct domain_c
    1.81  
    1.82      libxl_domain_build_state state;
    1.83      libxl_device_model_info dm_info;
    1.84 -    libxl_device_console console;
    1.85  
    1.86      int debug = dom_info->debug;
    1.87      int daemonize = dom_info->daemonize;
    1.88 @@ -1651,26 +1661,35 @@ start:
    1.89          }
    1.90      }
    1.91      if (d_config.c_info.hvm) {
    1.92 +        libxl_device_console console;
    1.93 +
    1.94          init_console_info(&console, 0, &state);
    1.95          console.domid = domid;
    1.96          libxl_device_console_add(&ctx, domid, &console);
    1.97 +        libxl_device_console_destroy(&console);
    1.98 +
    1.99          dm_info.domid = domid;
   1.100          MUST( libxl_create_device_model(&ctx, &dm_info,
   1.101                                          d_config.disks, d_config.num_disks,
   1.102                                          d_config.vifs, d_config.num_vifs,
   1.103                                          &dm_starting) );
   1.104      } else {
   1.105 +        libxl_device_console console;
   1.106 +
   1.107          for (i = 0; i < d_config.num_vfbs; i++) {
   1.108              d_config.vfbs[i].domid = domid;
   1.109              libxl_device_vfb_add(&ctx, domid, &d_config.vfbs[i]);
   1.110              d_config.vkbs[i].domid = domid;
   1.111              libxl_device_vkb_add(&ctx, domid, &d_config.vkbs[i]);
   1.112          }
   1.113 +
   1.114          init_console_info(&console, 0, &state);
   1.115          console.domid = domid;
   1.116          if (d_config.num_vfbs)
   1.117               console.consback = LIBXL_CONSBACK_IOEMU;
   1.118          libxl_device_console_add(&ctx, domid, &console);
   1.119 +        libxl_device_console_destroy(&console);
   1.120 +
   1.121          if (d_config.num_vfbs)
   1.122              libxl_create_xenpv_qemu(&ctx, domid, d_config.vfbs, &dm_starting);
   1.123      }