提交 24ca8fae 编写于 作者: P Peter Krempa

qemu-blockjob: Fix limit of bandwidth for block jobs to supported value

The JSON generator is able to represent only values less than LLONG_MAX, fix the
bandwidth limit checks when converting to value to catch overflows before they
reach the generator.
上级 ad5298e1
...@@ -2889,12 +2889,13 @@ qemuMonitorDriveMirror(qemuMonitorPtr mon, ...@@ -2889,12 +2889,13 @@ qemuMonitorDriveMirror(qemuMonitorPtr mon,
"flags=%x", "flags=%x",
mon, device, file, NULLSTR(format), bandwidth, flags); mon, device, file, NULLSTR(format), bandwidth, flags);
/* Convert bandwidth MiB to bytes */ /* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
* limited to LLONG_MAX also for unsigned values */
speed = bandwidth; speed = bandwidth;
if (speed > ULLONG_MAX / 1024 / 1024) { if (speed > LLONG_MAX >> 20) {
virReportError(VIR_ERR_OVERFLOW, virReportError(VIR_ERR_OVERFLOW,
_("bandwidth must be less than %llu"), _("bandwidth must be less than %llu"),
ULLONG_MAX / 1024 / 1024); LLONG_MAX >> 20);
return -1; return -1;
} }
speed <<= 20; speed <<= 20;
...@@ -2936,12 +2937,13 @@ qemuMonitorBlockCommit(qemuMonitorPtr mon, const char *device, ...@@ -2936,12 +2937,13 @@ qemuMonitorBlockCommit(qemuMonitorPtr mon, const char *device,
VIR_DEBUG("mon=%p, device=%s, top=%s, base=%s, bandwidth=%ld", VIR_DEBUG("mon=%p, device=%s, top=%s, base=%s, bandwidth=%ld",
mon, device, NULLSTR(top), NULLSTR(base), bandwidth); mon, device, NULLSTR(top), NULLSTR(base), bandwidth);
/* Convert bandwidth MiB to bytes */ /* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
* limited to LLONG_MAX also for unsigned values */
speed = bandwidth; speed = bandwidth;
if (speed > ULLONG_MAX / 1024 / 1024) { if (speed > LLONG_MAX >> 20) {
virReportError(VIR_ERR_OVERFLOW, virReportError(VIR_ERR_OVERFLOW,
_("bandwidth must be less than %llu"), _("bandwidth must be less than %llu"),
ULLONG_MAX / 1024 / 1024); LLONG_MAX >> 20);
return -1; return -1;
} }
speed <<= 20; speed <<= 20;
...@@ -3056,12 +3058,13 @@ int qemuMonitorBlockJob(qemuMonitorPtr mon, ...@@ -3056,12 +3058,13 @@ int qemuMonitorBlockJob(qemuMonitorPtr mon,
"modern=%d", mon, device, NULLSTR(base), bandwidth, info, mode, "modern=%d", mon, device, NULLSTR(base), bandwidth, info, mode,
modern); modern);
/* Convert bandwidth MiB to bytes */ /* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
* limited to LLONG_MAX also for unsigned values */
speed = bandwidth; speed = bandwidth;
if (speed > ULLONG_MAX / 1024 / 1024) { if (speed > LLONG_MAX >> 20) {
virReportError(VIR_ERR_OVERFLOW, virReportError(VIR_ERR_OVERFLOW,
_("bandwidth must be less than %llu"), _("bandwidth must be less than %llu"),
ULLONG_MAX / 1024 / 1024); LLONG_MAX >> 20);
return -1; return -1;
} }
speed <<= 20; speed <<= 20;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册