[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] qemu: fix inf-loop in blkio parameters



On Wed, Dec 28, 2011 at 06:57:34AM -0700, Eric Blake wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=770520
> 
> We had two nested loops both trying to use 'i' as the iteration
> variable, which can result in an infinite loop when the inner
> loop interferes with the outer loop.  Introduced in commit 93ab585.
> 
> * src/qemu/qemu_driver.c (qemuDomainSetBlkioParameters): Don't
> reuse iteration variable across two loops.
> ---
> 
> Pushing under the trivial rule.
> 
>  src/qemu/qemu_driver.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index eeeb935..a840c1f 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -5982,6 +5982,8 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
>              } else if (STREQ(param->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
>                  size_t ndevices;
>                  virBlkioDeviceWeightPtr devices = NULL;
> +                int j;
> +
>                  if (param->type != VIR_TYPED_PARAM_STRING) {
>                      qemuReportError(VIR_ERR_INVALID_ARG, "%s",
>                                      _("invalid type for device_weight tunable, "
> @@ -5996,19 +5998,19 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom,
>                      ret = -1;
>                      continue;
>                  }
> -                for (i = 0; i < ndevices; i++) {
> +                for (j = 0; j < ndevices; i++) {
>                      rc = virCgroupSetBlkioDeviceWeight(group,
> -                                                       devices[i].path,
> -                                                       devices[i].weight);
> +                                                       devices[j].path,
> +                                                       devices[j].weight);
>                      if (rc < 0) {
>                          virReportSystemError(-rc,
>                                               _("Unable to set io device weight "
>                                                 "for path %s"),
> -                                             devices[i].path);
> +                                             devices[j].path);
>                          break;
>                      }
>                  }
> -                if (i != ndevices) {
> +                if (j != ndevices) {
>                      ret = -1;
>                      continue;
>                  }

  Oops ! Good catch !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]