]> Git Repo - qemu.git/commitdiff
qom: code hardening - have bound checking while looping with integer value
authorAni Sinha <[email protected]>
Mon, 21 Sep 2020 09:33:25 +0000 (15:03 +0530)
committerEduardo Habkost <[email protected]>
Thu, 10 Dec 2020 22:32:26 +0000 (17:32 -0500)
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 <[email protected]>
Signed-off-by: Eduardo Habkost <[email protected]>
Reviewed-by: Daniel P. BerrangĂ© <[email protected]>
Message-Id: <20200921093325[email protected]>
Signed-off-by: Eduardo Habkost <[email protected]>
qom/object.c

index 10653552334549241cd5672d7a027ad57432c482..e73d70a9933e0479189c2a35db391f4b40fa74fa 100644 (file)
@@ -1196,11 +1196,11 @@ object_property_try_add(Object *obj, const char *name, const char *type,
 
     if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
         int i;
-        ObjectProperty *ret;
+        ObjectProperty *ret = NULL;
         char *name_no_array = g_strdup(name);
 
         name_no_array[name_len - 3] = '\0';
-        for (i = 0; ; ++i) {
+        for (i = 0; i < INT16_MAX; ++i) {
             char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
 
             ret = object_property_try_add(obj, full_name, type, get, set,
@@ -1211,6 +1211,7 @@ object_property_try_add(Object *obj, const char *name, const char *type,
             }
         }
         g_free(name_no_array);
+        assert(ret);
         return ret;
     }
 
This page took 0.024897 seconds and 4 git commands to generate.