xen: avoid PATH_MAX-sized array

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.
This commit is contained in:
Eric Blake 2011-06-22 14:31:45 -06:00
parent ca8b4cec6d
commit 565c975f9b
2 changed files with 18 additions and 5 deletions

View File

@ -1,7 +1,7 @@
/* /*
* xen_unified.c: Unified Xen driver. * 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 * See COPYING.LIB for the License of this software
* *
@ -117,7 +117,7 @@ struct xenUnifiedDriver {
typedef struct xenXMConfCache *xenXMConfCachePtr; typedef struct xenXMConfCache *xenXMConfCachePtr;
typedef struct xenXMConfCache { typedef struct xenXMConfCache {
time_t refreshedAt; time_t refreshedAt;
char filename[PATH_MAX]; char *filename;
virDomainDefPtr def; virDomainDefPtr def;
} xenXMConfCache; } xenXMConfCache;

View File

@ -143,6 +143,7 @@ static int xenInotifyActive(virConnectPtr conn)
static void xenXMConfigFree(void *payload, const void *key ATTRIBUTE_UNUSED) { static void xenXMConfigFree(void *payload, const void *key ATTRIBUTE_UNUSED) {
xenXMConfCachePtr entry = (xenXMConfCachePtr)payload; xenXMConfCachePtr entry = (xenXMConfCachePtr)payload;
virDomainDefFree(entry->def); virDomainDefFree(entry->def);
VIR_FREE(entry->filename);
VIR_FREE(entry); VIR_FREE(entry);
} }
@ -281,7 +282,11 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
virReportOOMError(); virReportOOMError();
return -1; return -1;
} }
memcpy(entry->filename, filename, PATH_MAX); if ((entry->filename = strdup(filename)) == NULL) {
virReportOOMError();
VIR_FREE(entry);
return -1;
}
} }
entry->refreshedAt = now; entry->refreshedAt = now;
@ -289,6 +294,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
VIR_DEBUG("Failed to read %s", entry->filename); VIR_DEBUG("Failed to read %s", entry->filename);
if (!newborn) if (!newborn)
virHashSteal(priv->configCache, filename); virHashSteal(priv->configCache, filename);
VIR_FREE(entry->filename);
VIR_FREE(entry); VIR_FREE(entry);
return -1; return -1;
} }
@ -298,6 +304,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
if (newborn) { if (newborn) {
if (virHashAddEntry(priv->configCache, entry->filename, entry) < 0) { if (virHashAddEntry(priv->configCache, entry->filename, entry) < 0) {
virDomainDefFree(entry->def); virDomainDefFree(entry->def);
VIR_FREE(entry->filename);
VIR_FREE(entry); VIR_FREE(entry);
xenXMError(VIR_ERR_INTERNAL_ERROR, xenXMError(VIR_ERR_INTERNAL_ERROR,
"%s", _("xenXMConfigCacheRefresh: virHashAddEntry")); "%s", _("xenXMConfigCacheRefresh: virHashAddEntry"));
@ -309,9 +316,11 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
* of the domain in question * of the domain in question
*/ */
if (!virHashLookup(priv->nameConfigMap, entry->def->name)) { 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); virHashSteal(priv->configCache, filename);
virDomainDefFree(entry->def); virDomainDefFree(entry->def);
VIR_FREE(entry->filename);
VIR_FREE(entry); VIR_FREE(entry);
} }
} }
@ -1171,7 +1180,10 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
goto error; goto error;
} }
memmove(entry->filename, filename, PATH_MAX); if ((entry->filename = strdup(filename)) == NULL) {
virReportOOMError();
goto error;
}
entry->def = def; entry->def = def;
if (virHashAddEntry(priv->configCache, filename, entry) < 0) { if (virHashAddEntry(priv->configCache, filename, entry) < 0) {
@ -1194,6 +1206,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
error: error:
VIR_FREE(filename); VIR_FREE(filename);
VIR_FREE(entry->filename);
VIR_FREE(entry); VIR_FREE(entry);
virDomainDefFree(def); virDomainDefFree(def);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);