mirror of https://gitee.com/openkylin/libvirt.git
virsh: Fix integer overflow in allocpages
I've came across an aarch64 system which supports hugepages up to 16GiB of size. However, I was unable to allocate them using virsh allocpages. This is because cmdAllocpages() uses vshCommandOptScaledInt(), which scales passed value into bytes, but since the virNodeAllocPages() expects size in KiB the variable holding bytes is then divided by 1024. However, the limit for the biggest value passed to vshCommandOptScaledInt() is UINT_MAX which is now obviously wrong, as it needs to be UINT_MAX * 1024. The same bug is in completer. But here, let's use ULLONG_MAX so that we don't have to care about it anymore. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
49156f8070
commit
d5f81479a6
|
@ -42,7 +42,7 @@ virshPagesizeNodeToString(xmlNodePtr node)
|
||||||
unit = virXMLPropString(node, "unit");
|
unit = virXMLPropString(node, "unit");
|
||||||
if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0)
|
if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0)
|
if (virScaleInteger(&byteval, unit, 1024, ULLONG_MAX) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
size = vshPrettyCapacity(byteval, &suffix);
|
size = vshPrettyCapacity(byteval, &suffix);
|
||||||
ret = g_strdup_printf("%.0f%s", size, suffix);
|
ret = g_strdup_printf("%.0f%s", size, suffix);
|
||||||
|
|
|
@ -488,7 +488,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
|
||||||
if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0)
|
if (cellno && vshCommandOptInt(ctl, cmd, "cellno", &startCell) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX) < 0)
|
if (vshCommandOptScaledInt(ctl, cmd, "pagesize", &tmp, 1024, UINT_MAX * 1024ULL) < 0)
|
||||||
return false;
|
return false;
|
||||||
pageSizes[0] = VIR_DIV_UP(tmp, 1024);
|
pageSizes[0] = VIR_DIV_UP(tmp, 1024);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue