[PATCH 6/7] virHostCPUGetCPUID: Limit the buffer size ranges

Peter Krempa pkrempa at redhat.com
Mon Apr 25 13:28:30 UTC 2022


Raise the lower bound to '64' as that seems to currently be the first
size that can fit the CPU data for a modern cpu.

Lower the upper bound to an arbitrary 65536. So many cpu features ougth
to be enough for everyone.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virhostcpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index aa21c567be..9a9fcf11c0 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -1360,7 +1360,7 @@ virHostCPUGetCPUID(void)
      * the 'nent' field is adjusted and an error (ENOMEM) is returned.  If the
      * number is just right, the 'nent' field is adjusted to the number of valid
      * entries in the 'entries' array, which is then filled. */
-    for (alloc_size = 1; alloc_size < INT32_MAX; alloc_size *= 2) {
+    for (alloc_size = 64; alloc_size <= 65536; alloc_size *= 2) {
         g_autofree struct kvm_cpuid2 *kvm_cpuid = NULL;

         kvm_cpuid = g_malloc0(sizeof(struct kvm_cpuid2) +
-- 
2.35.1



More information about the libvir-list mailing list