[libvirt] [PATCH] vmware: make version parsing more robust

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 | 10 ++++++++-- tests/vmwareverdata/workstation-7.0.0-with-garbage.txt | 3 +++ tests/vmwarevertest.c | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/vmwareverdata/workstation-7.0.0-with-garbage.txt diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 5ff6396..1f6f3bd 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -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 index 0000000..b3c8085 --- /dev/null +++ b/tests/vmwareverdata/workstation-7.0.0-with-garbage.txt @@ -0,0 +1,3 @@ +garbage line +VMware Workstation 7.0.0 build-203739 Release +garbage line diff --git a/tests/vmwarevertest.c b/tests/vmwarevertest.c index 16e48de..24de9e1 100644 --- a/tests/vmwarevertest.c +++ b/tests/vmwarevertest.c @@ -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; -- 1.8.5.3

On 04/09/2014 11:59 AM, Jean-Baptiste Rouault wrote:
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.
For libvirt's debug messages, we have virLogProbablyLogMessage that can check if the message matches libvirt's format. Should we really ignore all garbage? Jan

On Monday 28 April 2014 13:46:54 Ján Tomko wrote:
On 04/09/2014 11:59 AM, Jean-Baptiste Rouault wrote:
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.
For libvirt's debug messages, we have virLogProbablyLogMessage that can check if the message matches libvirt's format.
Should we really ignore all garbage?
Honestly I don't know, but as of today the only garbage I saw there was from libvirt. Apart from the version string, I don't think there could be useful information in the command output. Regards, Jean-Baptiste -- Jean-Baptiste ROUAULT R&D Engineer - diateam : Architectes de l'information Phone : +33 (0)2 98 050 050 Fax : +33 (0)2 98 050 051

On 06/09/2014 10:12 AM, Jean-Baptiste Rouault wrote:
On Monday 28 April 2014 13:46:54 Ján Tomko wrote:
On 04/09/2014 11:59 AM, Jean-Baptiste Rouault wrote:
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.
For libvirt's debug messages, we have virLogProbablyLogMessage that can check if the message matches libvirt's format.
Should we really ignore all garbage?
Honestly I don't know, but as of today the only garbage I saw there was from libvirt. Apart from the version string, I don't think there could be useful information in the command output.
It's probably not worth the trouble. ACK to your patch, I will push later today. Jan
participants (2)
-
Jean-Baptiste Rouault
-
Ján Tomko