]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Libvirt: virTypedParamsValidate: Fix detection of multiple parameters
authorJason J. Herne <jjherne@linux.vnet.ibm.com>
Tue, 12 Apr 2016 14:13:27 +0000 (10:13 -0400)
committerCole Robinson <crobinso@redhat.com>
Wed, 20 Apr 2016 13:30:25 +0000 (09:30 -0400)
commit791c90cb8d0596939e275b52656c383e9c9b63c2
treead2933f2cd61be144df21345676babae688c6f8a
parent58650d53c7974bf289a5f13c7f437cf9dd67d5a7
Libvirt: virTypedParamsValidate: Fix detection of multiple parameters

virTypedParamsValidate currently uses an index based check to find
duplicate parameters. This check does not work. Consider the following
simple example:

We have only 2 keys
A  (multiples allowed)
B  (multiples NOT allowed)

We are given the following list of parameters to check:
A
A
B

If you work through the validation loop you will see that our last iteration
through the loop has i=2 and j=1. In this case, i > j and keys[j].value.i will
indicate that multiples are not allowed. Both conditionals are satisfied so
an incorrect error will be given: "parameter '%s' occurs multiple times"

This patch replaces the index based check with code that remembers
the name of the last parameter seen and only triggers the error case if
the current parameter name equals the last one. This works because the
list is sorted and duplicate parameters will be grouped together.

In reality, we hit this bug while using selective block migration to migrate
a guest with 5 disks. 5 was apparently just the right number to push i > j
and hit this bug.

virsh migrate --live guestname --copy-storage-all
              --migrate-disks vdb,vdc,vdd,vde,vdf
              qemu+ssh://dsthost/system

Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Reviewed-by: Eric Farman <farman@linux.vnet.ibm.com>
(cherry picked from commit 0e570a6acc13ebbca913e69026f1468daf28240f)
src/util/virtypedparam.c
tests/virtypedparamtest.c