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

Daniel Veillard veillard at redhat.com
Mon Aug 2 15:30:54 UTC 2010


  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

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
-------------- next part --------------
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);
+            }
             break;
         case 'h':
             help = 1;


More information about the libvir-list mailing list