]> git.ipfire.org Git - thirdparty/libvirt.git/commit
domain_capabilities: Assert enums fit into unsigned int bitmask
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Nov 2020 10:58:01 +0000 (11:58 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 19 Nov 2020 13:31:12 +0000 (14:31 +0100)
commit912421e7b63a358d552b79fac62a5518ec58f4e5
treead8bc551b3533852704ed163b81ad945cfc18fa8
parent1fdbd4047efea78206dfd3e8f8673ca3b3ba1469
domain_capabilities: Assert enums fit into unsigned int bitmask

The way our domain capabilities work currently, is that we have
virDomainCapsEnum struct which contains 'unsigned int values'
member which serves as a bitmask. More complicated structs are
composed from this struct, giving us whole virDomainCaps
eventually.

Whenever we want to report that a certain value is supported, the
'1 << value' bit is set in the corresponding unsigned int member.
This works as long as the resulting value after bitshift does not
overflow unsigned int. There is a check inside
virDomainCapsEnumSet() which ensures exactly this, but no caller
really checks whether virDomainCapsEnumSet() succeeded. Also,
checking at runtime is a bit too late.

Fortunately, we know the largest value we want to store in each
member, because each enum of ours ends with _LAST member.
Therefore, we can check at build time whether an overflow can
occur.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/conf/domain_capabilities.h