From 9b9089991520e7f047404b8812af2aec7cb6e71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 9 Apr 2015 10:48:49 +0200 Subject: [PATCH] Split out storage format 'compat' attribute sanity check For future reuse in the snapshot XML. --- src/conf/storage_conf.c | 16 ++-------------- src/util/virstoragefile.c | 29 +++++++++++++++++++++++++++++ src/util/virstoragefile.h | 1 + 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 339f08f42d..990a528f23 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1374,20 +1374,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, } ret->target.compat = virXPathString("string(./target/compat)", ctxt); - if (ret->target.compat) { - 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; - } - virStringFreeList(version); - } + if (virStorageFileCheckCompat(ret->target.compat) < 0) + goto error; if (virXPathNode("./target/nocow", ctxt)) ret->target.nocow = true; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 96be02e66e..824cf5dcab 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2873,3 +2873,32 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top, VIR_FREE(tmp); 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; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index b4c3808683..aa17a00e54 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -384,4 +384,5 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from, char **relpath) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int virStorageFileCheckCompat(const char *compat); #endif /* __VIR_STORAGE_FILE_H__ */ -- GitLab