]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: check if domiftune parameters fit into UINT
authorJán Tomko <jtomko@redhat.com>
Thu, 26 Jun 2014 08:06:57 +0000 (10:06 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 4 Aug 2014 14:59:27 +0000 (16:59 +0200)
We parse the bandwidth rates as unsinged long long,
then try to fit them in VIR_TYPED_PARAM_UINT.

Report an error if they exceed UINT_MAX instead of
quietly using wrong values.

https://bugzilla.redhat.com/show_bug.cgi?id=1043735

tools/virsh-domain.c

index ad68aabf492157d150b15228a8c1c1b868d90293..f7193cb560e019466fd9464312db9eac7ed871c5 100644 (file)
@@ -2686,6 +2686,14 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
             vshError(ctl, _("inbound format is incorrect"));
             goto cleanup;
         }
+        /* we parse the rate as unsigned long long, but the API
+         * only accepts UINT */
+        if (inbound.average > UINT_MAX || inbound.peak > UINT_MAX ||
+            inbound.burst > UINT_MAX) {
+            vshError(ctl, _("inbound rate larger than maximum %u"),
+                     UINT_MAX);
+            goto cleanup;
+        }
         if (inbound.average == 0 && (inbound.burst || inbound.peak)) {
             vshError(ctl, _("inbound average is mandatory"));
             goto cleanup;
@@ -2714,6 +2722,12 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd)
             vshError(ctl, _("outbound format is incorrect"));
             goto cleanup;
         }
+        if (outbound.average > UINT_MAX || outbound.peak > UINT_MAX ||
+            outbound.burst > UINT_MAX) {
+            vshError(ctl, _("outbound rate larger than maximum %u"),
+                     UINT_MAX);
+            goto cleanup;
+        }
         if (outbound.average == 0 && (outbound.burst || outbound.peak)) {
             vshError(ctl, _("outbound average is mandatory"));
             goto cleanup;