On 07/30/2015 03:29 PM, Andrea Bolognani wrote:
On Thu, 2015-07-30 at 10:57 +0800, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1248277
When count <= 0, the client exit without set an error.
Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
tools/virsh-domain.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f7edeeb..b6da684 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6744,8 +6744,12 @@ cmdSetvcpus(vshControl *ctl, const vshCmd
*cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <=
0)
+ if (vshCommandOptInt(ctl, cmd, "count", &count) < 0)
goto cleanup;
+ if (count <= 0) {
+ vshError(ctl, _("Invalid value '%d' for number of virtual
CPUs"), count);
+ goto cleanup;
+ }
/* none of the options were specified */
if (!current && flags == 0) {
Nice catch, but I would go for the following diff instead:
-----8<-----
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a61656f..4b8ebbd 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6819,7 +6819,7 @@ static bool
cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
- int count = 0;
+ unsigned int count = 0;
bool ret = false;
bool maximum = vshCommandOptBool(cmd, "maximum");
bool config = vshCommandOptBool(cmd, "config");
@@ -6846,8 +6846,15 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (vshCommandOptInt(ctl, cmd, "count", &count) < 0 || count <= 0)
+ if (vshCommandOptUInt(ctl, cmd, "count", &count) < 0)
+ goto cleanup;
+
+ if (count == 0) {
+ vshError(ctl,
+ _("Numeric value '%s' for <%s> option is malformed or
out of range"),
+ "0", "count");
goto cleanup;
+ }
/* none of the options were specified */
if (!current && flags == 0) {
----->8-----
It's slightly more awkward, but his way we make sure the
error message is the same whether the value used for the
count option is "foo", "0" or "-20". vshCommandOptUInt()
already uses that error message internally.
Does it look good to you?
I think a clear error is works for me, i am not good at the error
message for a long time ;)
Thanks a lot for your quick review.
Cheers.
Luyao
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list