[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Check that virsh -d argument is numeric

  Having been bitten one more time by the use of -d to pass the
hypervisor URI instead of -c (confusion coming from CVS using
-d to specify the root), I suggest to drop atoi and use the
function with checking and error out with proper explanation instead
of silently failing !

paphio:~/libvirt -> /usr/bin/virsh -d qemu+ssh://test2/system list
 Id Name                 State

paphio:~/libvirt -> tools/virsh -d qemu+ssh://test2/system list
error: option -d take a numeric argument
paphio:~/libvirt -> tools/virsh -d 5 list
command: "list "
 Id Name                 State

paphio:~/libvirt ->


Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
diff --git a/tools/virsh.c b/tools/virsh.c
index 354feb0..926652a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -11021,7 +11021,10 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
     while ((arg = getopt_long(end, argv, "d:hqtc:vrl:", opt, &idx)) != -1) {
         switch (arg) {
         case 'd':
-            ctl->debug = atoi(optarg);
+            if (virStrToLong_i(optarg, NULL, 10, &ctl->debug) < 0) {
+                vshError(ctl, _("option -d takes a numeric argument"), arg);
+                exit(EXIT_FAILURE);
+            }
         case 'h':
             help = 1;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]