]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Fix overflow error of freepages command
authorAdam Julis <ajulis@redhat.com>
Tue, 5 Mar 2024 10:43:03 +0000 (11:43 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Mar 2024 11:22:06 +0000 (12:22 +0100)
Trying to print pages of a size larger than the UINT_MAX of the
given platform (for example, 4G on 64-bit ARM), results in a
system error even though this is a legitimate request.

The vshCommandOptScaledInt() used for parsing the pagesize is
given UINT_MAX as the upper limit. The parsed value is then
divided by 1024 and fed to virNodeGetFreePages() which expects an
unsigned int. We can't change the public API but the upper limit
can be raised by the factor of 1024.

Resolves: https://issues.redhat.com/browse/RHEL-23608

Signed-off-by: Adam Julis <ajulis@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-host.c

index 6c14be865f612db078ee71bd08f9e2a1f01496ef..90ff46c5c4fa2bd4ce793a8f1a9c5177deb26f0b 100644 (file)
@@ -335,8 +335,10 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
 
     VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
 
-    if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0)
+    if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &bytes,
+                               1024, UINT_MAX * 1024ULL) < 0) {
         goto cleanup;
+    }
     kibibytes = VIR_DIV_UP(bytes, 1024);
 
     if (all) {