virsh: Fix overflow error of freepages command

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>
This commit is contained in:
Adam Julis 2024-03-05 11:43:03 +01:00 committed by Michal Privoznik
parent ba3a5604c9
commit bdee774285

View 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) {