提交 9b908999 编写于 作者: J Ján Tomko

Split out storage format 'compat' attribute sanity check

For future reuse in the snapshot XML.
上级 b77ce18a
...@@ -1374,20 +1374,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, ...@@ -1374,20 +1374,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
} }
ret->target.compat = virXPathString("string(./target/compat)", ctxt); ret->target.compat = virXPathString("string(./target/compat)", ctxt);
if (ret->target.compat) { if (virStorageFileCheckCompat(ret->target.compat) < 0)
char **version = virStringSplit(ret->target.compat, ".", 2);
unsigned int result;
if (!version || !version[1] ||
virStrToLong_ui(version[0], NULL, 10, &result) < 0 ||
virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
virStringFreeList(version);
virReportError(VIR_ERR_XML_ERROR, "%s",
_("forbidden characters in 'compat' attribute"));
goto error; goto error;
}
virStringFreeList(version);
}
if (virXPathNode("./target/nocow", ctxt)) if (virXPathNode("./target/nocow", ctxt))
ret->target.nocow = true; ret->target.nocow = true;
......
...@@ -2873,3 +2873,32 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top, ...@@ -2873,3 +2873,32 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
VIR_FREE(tmp); VIR_FREE(tmp);
return ret; return ret;
} }
/*
* virStorageFileCheckCompat
*/
int
virStorageFileCheckCompat(const char *compat)
{
char **version;
unsigned int result;
int ret = -1;
if (!compat)
return 0;
version = virStringSplit(compat, ".", 2);
if (!version || !version[1] ||
virStrToLong_ui(version[0], NULL, 10, &result) < 0 ||
virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("forbidden characters in 'compat' attribute"));
goto cleanup;
}
ret = 0;
cleanup:
virStringFreeList(version);
return ret;
}
...@@ -384,4 +384,5 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from, ...@@ -384,4 +384,5 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from,
char **relpath) char **relpath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int virStorageFileCheckCompat(const char *compat);
#endif /* __VIR_STORAGE_FILE_H__ */ #endif /* __VIR_STORAGE_FILE_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册