virsh: error out on non-numeric timeout values

Some block commands and migrate ignored incorrect values.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=927495
This commit is contained in:
Ján Tomko 2013-03-26 16:41:06 +01:00
parent ceb31795af
commit 41db895f9e

View File

@ -1495,14 +1495,14 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
const char *path = NULL; const char *path = NULL;
bool quit = false; bool quit = false;
int abort_flags = 0; int abort_flags = 0;
int rv;
if (blocking) { if (blocking) {
if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) { if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
if (timeout < 1) { (rv > 0 && timeout < 1)) {
vshError(ctl, "%s", _("invalid timeout")); vshError(ctl, "%s", _("invalid timeout"));
return false; return false;
} } else if (rv > 0) {
/* Ensure that we can multiply by 1000 without overflowing. */ /* Ensure that we can multiply by 1000 without overflowing. */
if (timeout > INT_MAX / 1000) { if (timeout > INT_MAX / 1000) {
vshError(ctl, "%s", _("timeout is too big")); vshError(ctl, "%s", _("timeout is too big"));
@ -1685,18 +1685,18 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
const char *path = NULL; const char *path = NULL;
bool quit = false; bool quit = false;
int abort_flags = 0; int abort_flags = 0;
int rv;
if (blocking) { if (blocking) {
if (pivot && finish) { if (pivot && finish) {
vshError(ctl, "%s", _("cannot mix --pivot and --finish")); vshError(ctl, "%s", _("cannot mix --pivot and --finish"));
return false; return false;
} }
if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) { if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
if (timeout < 1) { (rv > 0 && timeout < 1)) {
vshError(ctl, "%s", _("invalid timeout")); vshError(ctl, "%s", _("invalid timeout"));
return false; return false;
} } else if (rv > 0) {
/* Ensure that we can multiply by 1000 without overflowing. */ /* Ensure that we can multiply by 1000 without overflowing. */
if (timeout > INT_MAX / 1000) { if (timeout > INT_MAX / 1000) {
vshError(ctl, "%s", _("timeout is too big")); vshError(ctl, "%s", _("timeout is too big"));
@ -1962,14 +1962,14 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
const char *path = NULL; const char *path = NULL;
bool quit = false; bool quit = false;
int abort_flags = 0; int abort_flags = 0;
int rv;
if (blocking) { if (blocking) {
if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) { if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
if (timeout < 1) { (rv > 0 && timeout < 1)) {
vshError(ctl, "%s", _("invalid timeout")); vshError(ctl, "%s", _("invalid timeout"));
return false; return false;
} } else if (rv > 0) {
/* Ensure that we can multiply by 1000 without overflowing. */ /* Ensure that we can multiply by 1000 without overflowing. */
if (timeout > INT_MAX / 1000) { if (timeout > INT_MAX / 1000) {
vshError(ctl, "%s", _("timeout is too big")); vshError(ctl, "%s", _("timeout is too big"));
@ -8456,6 +8456,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
int timeout = 0; int timeout = 0;
bool live_flag = false; bool live_flag = false;
vshCtrlData data; vshCtrlData data;
int rv;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
@ -8465,18 +8466,17 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "live")) if (vshCommandOptBool(cmd, "live"))
live_flag = true; live_flag = true;
if (vshCommandOptInt(cmd, "timeout", &timeout) > 0) { if ((rv = vshCommandOptInt(cmd, "timeout", &timeout)) < 0 ||
(rv > 0 && timeout < 1)) {
vshError(ctl, "%s", _("migrate: Invalid timeout"));
goto cleanup;
} else if (rv > 0) {
if (! live_flag) { if (! live_flag) {
vshError(ctl, "%s", vshError(ctl, "%s",
_("migrate: Unexpected timeout for offline migration")); _("migrate: Unexpected timeout for offline migration"));
goto cleanup; goto cleanup;
} }
if (timeout < 1) {
vshError(ctl, "%s", _("migrate: Invalid timeout"));
goto cleanup;
}
/* Ensure that we can multiply by 1000 without overflowing. */ /* Ensure that we can multiply by 1000 without overflowing. */
if (timeout > INT_MAX / 1000) { if (timeout > INT_MAX / 1000) {
vshError(ctl, "%s", _("migrate: Timeout is too big")); vshError(ctl, "%s", _("migrate: Timeout is too big"));