From: Peter Krempa Date: Tue, 17 Sep 2013 09:16:30 +0000 (+0200) Subject: conf: Don't corrupt metadata on OOM X-Git-Tag: CVE-2013-4311~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7655ed0802eecc3d8486a0360d2326ecd052e477;p=thirdparty%2Flibvirt.git conf: Don't corrupt metadata on OOM Eric Blake suggested that we could do a little better in case copying of the metadata to be set fails. With this patch, the old metadata is discarded after the new string is copied successfuly. --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7e78068452..60f25abd67 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18599,19 +18599,24 @@ virDomainDefSetMetadata(virDomainDefPtr def, xmlDocPtr doc = NULL; xmlNodePtr old; xmlNodePtr new; + char *tmp; int ret = -1; switch ((virDomainMetadataType) type) { case VIR_DOMAIN_METADATA_DESCRIPTION: - VIR_FREE(def->description); - if (VIR_STRDUP(def->description, metadata) < 0) + if (VIR_STRDUP(tmp, metadata) < 0) goto cleanup; + + VIR_FREE(def->description); + def->description = tmp; break; case VIR_DOMAIN_METADATA_TITLE: - VIR_FREE(def->title); - if (VIR_STRDUP(def->title, metadata) < 0) + if (VIR_STRDUP(tmp, metadata) < 0) goto cleanup; + + VIR_FREE(def->title); + def->title = tmp; break; case VIR_DOMAIN_METADATA_ELEMENT: