See previous patch for why this is good... * src/xen/xen_driver.h (xenXMConfCache): Manage filename dynamically. * src/xen/xm_internal.c (xenXMConfigCacheAddFile) (xenXMConfigFree, xenXMDomainDefineXML): Likewise. --- src/xen/xen_driver.h | 4 ++-- src/xen/xm_internal.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h index 20eca6e..6d45f7d 100644 --- a/src/xen/xen_driver.h +++ b/src/xen/xen_driver.h @@ -1,7 +1,7 @@ /* * xen_unified.c: Unified Xen driver. * - * Copyright (C) 2007, 2010 Red Hat, Inc. + * Copyright (C) 2007, 2010-2011 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -117,7 +117,7 @@ struct xenUnifiedDriver { typedef struct xenXMConfCache *xenXMConfCachePtr; typedef struct xenXMConfCache { time_t refreshedAt; - char filename[PATH_MAX]; + char *filename; virDomainDefPtr def; } xenXMConfCache; diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 713bac3..530b0d4 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -143,6 +143,7 @@ static int xenInotifyActive(virConnectPtr conn) static void xenXMConfigFree(void *payload, const void *key ATTRIBUTE_UNUSED) { xenXMConfCachePtr entry = (xenXMConfCachePtr)payload; virDomainDefFree(entry->def); + VIR_FREE(entry->filename); VIR_FREE(entry); } @@ -281,7 +282,11 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) virReportOOMError(); return -1; } - memcpy(entry->filename, filename, PATH_MAX); + if ((entry->filename = strdup(filename)) == NULL) { + virReportOOMError(); + VIR_FREE(entry); + return -1; + } } entry->refreshedAt = now; @@ -289,6 +294,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) VIR_DEBUG("Failed to read %s", entry->filename); if (!newborn) virHashSteal(priv->configCache, filename); + VIR_FREE(entry->filename); VIR_FREE(entry); return -1; } @@ -298,6 +304,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) if (newborn) { if (virHashAddEntry(priv->configCache, entry->filename, entry) < 0) { virDomainDefFree(entry->def); + VIR_FREE(entry->filename); VIR_FREE(entry); xenXMError(VIR_ERR_INTERNAL_ERROR, "%s", _("xenXMConfigCacheRefresh: virHashAddEntry")); @@ -309,9 +316,11 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) * of the domain in question */ if (!virHashLookup(priv->nameConfigMap, entry->def->name)) { - if (virHashAddEntry(priv->nameConfigMap, entry->def->name, entry->filename) < 0) { + if (virHashAddEntry(priv->nameConfigMap, entry->def->name, + entry->filename) < 0) { virHashSteal(priv->configCache, filename); virDomainDefFree(entry->def); + VIR_FREE(entry->filename); VIR_FREE(entry); } } @@ -1171,7 +1180,10 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) goto error; } - memmove(entry->filename, filename, PATH_MAX); + if ((entry->filename = strdup(filename)) == NULL) { + virReportOOMError(); + goto error; + } entry->def = def; if (virHashAddEntry(priv->configCache, filename, entry) < 0) { @@ -1194,6 +1206,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) error: VIR_FREE(filename); + VIR_FREE(entry->filename); VIR_FREE(entry); virDomainDefFree(def); xenUnifiedUnlock(priv); -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list