[PATCH] 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, around 4G on 64-bit intel), a system error was printed, but this is a legitimate request, fixed. vshCommandOptScaledInt requiers set maximum returning size for the variable '&bytes'. It was set as UINT_MAX, while the public API variable 'kibibytes', which loads the 'bytes' lately, is type of UINT. Since it's kibibytes, the value in bytes should be 1024* bigger and it still will works correctly. So the correct max size of bytes is UINT_MAX * 1024. Resolves: https://issues.redhat.com/browse/RHEL-23608 Signed-off-by: Adam Julis <ajulis@redhat.com> --- tools/virsh-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 6c14be865f..5a934d7a7f 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -335,7 +335,7 @@ 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); -- 2.43.2

On 3/5/24 11:43, Adam Julis wrote:
Trying to print pages of a size larger than the UINT_MAX of the given platform (for example, around 4G on 64-bit intel), a system error was printed, but this is a legitimate request, fixed.
vshCommandOptScaledInt requiers set maximum returning size for the variable '&bytes'. It was set as UINT_MAX, while the public API variable 'kibibytes', which loads the 'bytes' lately, is type of UINT. Since it's kibibytes, the value in bytes should be 1024* bigger and it still will works correctly. So the correct max size of bytes is UINT_MAX * 1024.
Resolves: https://issues.redhat.com/browse/RHEL-23608
Signed-off-by: Adam Julis <ajulis@redhat.com> --- tools/virsh-host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 6c14be865f..5a934d7a7f 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -335,7 +335,7 @@ 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)
I've split this long line into two.
goto cleanup; kibibytes = VIR_DIV_UP(bytes, 1024);
Reworded the commit message a bit and merged. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Adam Julis
-
Michal Prívozník