esxPrivate *priv = conn->privateData;
if (virParseVersionString(priv->primary->service->about->version,
- version) < 0) {
+ version, false) < 0) {
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Could not parse version number from '%s'"),
priv->primary->service->about->version);
uname(&ver);
- if (virParseVersionString(ver.release, version) < 0) {
+ if (virParseVersionString(ver.release, version, true) < 0) {
lxcError(VIR_ERR_INTERNAL_ERROR, _("Unknown release: %s"), ver.release);
return -1;
}
if ((tmp = STRSKIP(tmp, "vzctl version ")) == NULL)
goto cleanup;
- if (virParseVersionString(tmp, &version) < 0)
+ if (virParseVersionString(tmp, &version, false) < 0)
goto cleanup;
if (retversion)
if (driver->umlVersion == 0) {
uname(&ut);
- if (virParseVersionString(ut.release, &driver->umlVersion) < 0) {
+ if (virParseVersionString(ut.release, &driver->umlVersion, true) < 0) {
umlReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse version %s"), ut.release);
goto cleanup;
* virParseVersionString:
* @str: const char pointer to the version string
* @version: unsigned long pointer to output the version number
+ * @allowMissing: true to treat 3 like 3.0.0, false to error out on
+ * missing minor or micro
*
* Parse an unsigned version number from a version string. Expecting
* 'major.minor.micro' format, ignoring an optional suffix.
* Returns the 0 for success, -1 for error.
*/
int
-virParseVersionString(const char *str, unsigned long *version)
+virParseVersionString(const char *str, unsigned long *version,
+ bool allowMissing)
{
unsigned int major, minor = 0, micro = 0;
char *tmp;
if (virStrToLong_ui(str, &tmp, 10, &major) < 0)
return -1;
+ if (!allowMissing && *tmp != '.')
+ return -1;
+
if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, &minor) < 0)
return -1;
+ if (!allowMissing && *tmp != '.')
+ return -1;
+
if ((*tmp == '.') && virStrToLong_ui(tmp + 1, &tmp, 10, µ) < 0)
return -1;
+ if (major > UINT_MAX / 1000000 || minor > 999 || micro > 999)
+ return -1;
+
*version = 1000000 * major + 1000 * minor + micro;
return 0;
void virSkipSpaces(const char **str);
int virParseNumber(const char **str);
-int virParseVersionString(const char *str, unsigned long *version);
+int virParseVersionString(const char *str, unsigned long *version,
+ bool allowMissing);
int virAsprintf(char **strp, const char *fmt, ...)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_FMT_PRINTF(2, 3);
int virVasprintf(char **strp, const char *fmt, va_list list)
}
}
- if (virParseVersionString(value, &vboxVersion) < 0) {
+ if (virParseVersionString(value, &vboxVersion, false) < 0) {
VIR_ERROR(_("Could not parse version number from '%s'"), value);
goto cleanup;
}
VBOX_UTF16_TO_UTF8(versionUtf16, &vboxVersion);
- if (virParseVersionString(vboxVersion, &data->version) >= 0)
+ if (virParseVersionString(vboxVersion, &data->version, false) >= 0)
ret = 0;
VBOX_UTF8_FREE(vboxVersion);
goto cleanup;
}
- if (virParseVersionString(tmp, &version) < 0) {
+ if (virParseVersionString(tmp, &version, false) < 0) {
vmwareError(VIR_ERR_INTERNAL_ERROR, "%s",
_("version parsing error"));
goto cleanup;
}
}
if (version) {
- if (virParseVersionString(version, hvVer) < 0)
+ if (virParseVersionString(version, hvVer, false) < 0)
xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR,
_("Couldn't parse version info"));
else