From be61ac8742d24a170a83340b576dbb39635133f6 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Thu, 22 Jan 2015 15:53:55 +0100 Subject: [PATCH] conf: Improve metadata type verification https://bugzilla.redhat.com/show_bug.cgi?id=1184929 Split out checking of invalid metadata type from the switch statement so that we can use the typecasted enum value to allow tracking addition of new items by the compliler. Also avoids two dead-code break statements. (cherry picked from commit 3738166603b2ab11ae30061381f378679b767758) Signed-off-by: Jiri Denemark --- src/conf/domain_conf.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 36b9ba7..47942ff 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18995,6 +18995,12 @@ virDomainObjGetMetadata(virDomainObjPtr vm, virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, NULL); + if (type >= VIR_DOMAIN_METADATA_LAST) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown metadata type '%d'"), type); + goto cleanup; + } + if (virDomainLiveConfigHelperMethod(caps, xmlopt, vm, &flags, &def) < 0) goto cleanup; @@ -19021,10 +19027,7 @@ virDomainObjGetMetadata(virDomainObjPtr vm, goto cleanup; break; - default: - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("unknown metadata type")); - goto cleanup; + case VIR_DOMAIN_METADATA_LAST: break; } @@ -19050,6 +19053,12 @@ virDomainDefSetMetadata(virDomainDefPtr def, char *tmp; int ret = -1; + if (type >= VIR_DOMAIN_METADATA_LAST) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown metadata type '%d'"), type); + goto cleanup; + } + switch ((virDomainMetadataType) type) { case VIR_DOMAIN_METADATA_DESCRIPTION: if (VIR_STRDUP(tmp, metadata) < 0) @@ -19103,10 +19112,7 @@ virDomainDefSetMetadata(virDomainDefPtr def, } break; - default: - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("unknown metadata type")); - goto cleanup; + case VIR_DOMAIN_METADATA_LAST: break; } -- 2.2.1