提交 aa286e53 编写于 作者: E Eric Blake

virStorageVol: avoid PATH_MAX-sized array

POSIX allows implementations where PATH_MAX is undefined, leading
to compilation error.  Not to mention that even if it is defined,
it is often wasteful in relation to the amount of data being stored.

All clients of vol->key were audited, and found not to care about
whether key is static or dynamic, except for these offenders:

* src/datatypes.h (struct _virStorageVol): Manage key dynamically.
* src/datatypes.c (virReleaseStorageVol): Free key.
(virGetStorageVol): Copy key.
上级 26dc216a
...@@ -738,10 +738,10 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, ...@@ -738,10 +738,10 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
if (virStrcpyStatic(ret->key, key) == NULL) { ret->key = strdup(key);
if (ret->key == NULL) {
virMutexUnlock(&conn->lock); virMutexUnlock(&conn->lock);
virLibConnError(VIR_ERR_INTERNAL_ERROR, virReportOOMError();
_("Volume key %s too large for destination"), key);
goto error; goto error;
} }
ret->magic = VIR_STORAGE_VOL_MAGIC; ret->magic = VIR_STORAGE_VOL_MAGIC;
...@@ -754,6 +754,7 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, ...@@ -754,6 +754,7 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
error: error:
if (ret != NULL) { if (ret != NULL) {
VIR_FREE(ret->key);
VIR_FREE(ret->name); VIR_FREE(ret->name);
VIR_FREE(ret->pool); VIR_FREE(ret->pool);
VIR_FREE(ret); VIR_FREE(ret);
...@@ -780,6 +781,7 @@ virReleaseStorageVol(virStorageVolPtr vol) { ...@@ -780,6 +781,7 @@ virReleaseStorageVol(virStorageVolPtr vol) {
VIR_DEBUG("release vol %p %s", vol, vol->name); VIR_DEBUG("release vol %p %s", vol, vol->name);
vol->magic = -1; vol->magic = -1;
VIR_FREE(vol->key);
VIR_FREE(vol->name); VIR_FREE(vol->name);
VIR_FREE(vol->pool); VIR_FREE(vol->pool);
VIR_FREE(vol); VIR_FREE(vol);
......
/* /*
* datatypes.h: management of structs for public data types * datatypes.h: management of structs for public data types
* *
* Copyright (C) 2006-2008, 2010 Red Hat, Inc. * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -254,8 +254,7 @@ struct _virStorageVol { ...@@ -254,8 +254,7 @@ struct _virStorageVol {
virConnectPtr conn; /* pointer back to the connection */ virConnectPtr conn; /* pointer back to the connection */
char *pool; /* Pool name of owner */ char *pool; /* Pool name of owner */
char *name; /* the storage vol external name */ char *name; /* the storage vol external name */
/* XXX currently abusing path for this. Ought not to be so evil */ char *key; /* unique key for storage vol */
char key[PATH_MAX]; /* unique key for storage vol */
}; };
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册