qom: code hardening - have bound checking while looping with integer value
authorAni Sinha <ani@anisinha.ca>
Mon, 21 Sep 2020 09:33:25 +0000 (15:03 +0530)
committerEduardo Habkost <ehabkost@redhat.com>
Thu, 10 Dec 2020 22:32:26 +0000 (17:32 -0500)
commit1bf8b88f144bee747e386c88d45d772e066bbb36
tree060d35f9e5e4eca60072e0a5c2931c43fd648b8e
parent2ecfc0657afa5d29a373271b342f704a1a3c6737
qom: code hardening - have bound checking while looping with integer value

Object property insertion code iterates over an integer to get an unused
index that can be used as an unique name for an object property. This loop
increments the integer value indefinitely. Although very unlikely, this can
still cause an integer overflow.
In this change, we fix the above code by checking against INT16_MAX and making
sure that the interger index does not overflow beyond that value. If no
available index is found, the code would cause an assertion failure. This
assertion failure is necessary because the callers of the function do not check
the return value for NULL.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200921093325.25617-1-ani@anisinha.ca>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
qom/object.c