]> xenbits.xensource.com Git - libvirt.git/commitdiff
vmware: make version parsing more robust
authorJean-Baptiste Rouault <jean-baptiste.rouault@diateam.net>
Wed, 9 Apr 2014 09:59:53 +0000 (11:59 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 11 Jun 2014 12:56:18 +0000 (14:56 +0200)
Since commit d69415d4, vmware version is parsed from both stdout and
stderr. This patch makes version parsing work even if there is garbage
(libvirt debug messages for example) in the command output.

Add test data for this case.

src/vmware/vmware_conf.c
tests/vmwareverdata/workstation-7.0.0-with-garbage.txt [new file with mode: 0644]
tests/vmwarevertest.c

index 29ca322a0dcea9bf58066c389eec4ec847afe092..b77330313be88b23cea52b74d83b8ac166233cb3 100644 (file)
@@ -1,7 +1,7 @@
 /*---------------------------------------------------------------------------*/
 /*
  * Copyright (C) 2011-2014 Red Hat, Inc.
- * Copyright 2010, diateam (www.diateam.net)
+ * Copyright (C) 2010-2014, diateam (www.diateam.net)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -241,7 +241,13 @@ vmwareParseVersionStr(int type, const char *verbuf, unsigned long *version)
             return -1;
     }
 
-    if ((tmp = STRSKIP(verbuf, pattern)) == NULL) {
+    if ((tmp = strstr(verbuf, pattern)) == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("cannot find version pattern \"%s\""), pattern);
+        return -1;
+    }
+
+    if ((tmp = STRSKIP(tmp, pattern)) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to parse %sversion"), pattern);
         return -1;
diff --git a/tests/vmwareverdata/workstation-7.0.0-with-garbage.txt b/tests/vmwareverdata/workstation-7.0.0-with-garbage.txt
new file mode 100644 (file)
index 0000000..b3c8085
--- /dev/null
@@ -0,0 +1,3 @@
+garbage line
+VMware Workstation 7.0.0 build-203739 Release
+garbage line
index 16e48deed0f9e48251c66f250edfe8bfde4fc6f2..24de9e1251d5a260ada6d949e1bbe86321936c1d 100644 (file)
@@ -88,6 +88,7 @@ mymain(void)
     } while (0)
 
     DO_TEST("ws", "workstation-7.0.0", 7000000);
+    DO_TEST("ws", "workstation-7.0.0-with-garbage", 7000000);
     DO_TEST("fusion", "fusion-5.0.3", 5000003);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;