diff --git a/ChangeLog b/ChangeLog index 9d516014cb..884dab9fba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue May 19 09:14:12 EDT 2009 Cole Robinson + + Use virAsprintf, rather than VIR_ALLOC + strcpy + strcat + * qemud/remote.c src/remote_internal.c src/storage_backend.c + src/storage_backend_fs.c src/storage_backend_logical.c + src/test.c + Tue May 19 09:04:05 EDT 2009 Cole Robinson * src/virsh.c: Don't validate disk type in virsh attach-disk diff --git a/qemud/remote.c b/qemud/remote.c index a92dea9b38..f9aa926f4f 100644 --- a/qemud/remote.c +++ b/qemud/remote.c @@ -52,7 +52,9 @@ #include "datatypes.h" #include "qemud.h" #include "memory.h" +#include "util.h" +#define VIR_FROM_THIS VIR_FROM_REMOTE #define REMOTE_DEBUG(fmt, ...) DEBUG(fmt, __VA_ARGS__) static void remoteDispatchFormatError (remote_error *rerr, @@ -2602,14 +2604,11 @@ static char *addrToString(remote_error *rerr, return NULL; } - if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) { - remoteDispatchOOMError(rerr); + if (virAsprintf(&addr, "%s;%s", host, port) == -1) { + virReportOOMError(NULL); return NULL; } - strcpy(addr, host); - strcat(addr, ";"); - strcat(addr, port); return addr; } diff --git a/src/remote_internal.c b/src/remote_internal.c index 1ca77841c0..542f4adaf8 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -5189,14 +5189,11 @@ static char *addrToString(struct sockaddr_storage *sa, socklen_t salen) return NULL; } - if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) { - virReportOOMError (NULL); + if (virAsprintf(&addr, "%s;%s", host, port) == -1) { + virReportOOMError(NULL); return NULL; } - strcpy(addr, host); - strcat(addr, ";"); - strcat(addr, port); return addr; } diff --git a/src/storage_backend.c b/src/storage_backend.c index 2db314dfab..96cf37ccac 100644 --- a/src/storage_backend.c +++ b/src/storage_backend.c @@ -342,17 +342,14 @@ virStorageBackendStablePath(virConnectPtr conn, if (dent->d_name[0] == '.') continue; - if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) + - 1 + strlen(dent->d_name) + 1) < 0) { + if (virAsprintf(&stablepath, "%s/%s", + pool->def->target.path, + dent->d_name) == -1) { virReportOOMError(conn); closedir(dh); return NULL; } - strcpy(stablepath, pool->def->target.path); - strcat(stablepath, "/"); - strcat(stablepath, dent->d_name); - if (virFileLinkPointsTo(stablepath, devpath)) { closedir(dh); return stablepath; diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c index fac43df6e4..ff1eac2956 100644 --- a/src/storage_backend_fs.c +++ b/src/storage_backend_fs.c @@ -668,14 +668,13 @@ virStorageBackendFileSystemMount(virConnectPtr conn, } if (pool->def->type == VIR_STORAGE_POOL_NETFS) { - if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) + - 1 + strlen(pool->def->source.dir) + 1) < 0) { + if (virAsprintf(&src, "%s:%s", + pool->def->source.host.name, + pool->def->source.dir) == -1) { virReportOOMError(conn); return -1; } - strcpy(src, pool->def->source.host.name); - strcat(src, ":"); - strcat(src, pool->def->source.dir); + } else { if ((src = strdup(pool->def->source.devices[0].path)) == NULL) { virReportOOMError(conn); @@ -829,13 +828,11 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn, vol->type = VIR_STORAGE_VOL_FILE; vol->target.format = VIR_STORAGE_VOL_FILE_RAW; /* Real value is filled in during probe */ - if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + - 1 + strlen(vol->name) + 1) < 0) + if (virAsprintf(&vol->target.path, "%s/%s", + pool->def->target.path, + vol->name) == -1) goto no_memory; - strcpy(vol->target.path, pool->def->target.path); - strcat(vol->target.path, "/"); - strcat(vol->target.path, vol->name); if ((vol->key = strdup(vol->target.path)) == NULL) goto no_memory; @@ -995,15 +992,15 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn, virStorageVolDefPtr vol) { - if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + - 1 + strlen(vol->name) + 1) < 0) { + vol->type = VIR_STORAGE_VOL_FILE; + + if (virAsprintf(&vol->target.path, "%s/%s", + pool->def->target.path, + vol->name) == -1) { virReportOOMError(conn); return -1; } - vol->type = VIR_STORAGE_VOL_FILE; - strcpy(vol->target.path, pool->def->target.path); - strcat(vol->target.path, "/"); - strcat(vol->target.path, vol->name); + vol->key = strdup(vol->target.path); if (vol->key == NULL) { virReportOOMError(conn); diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c index cbd27651ad..1bd00d4b2d 100644 --- a/src/storage_backend_logical.c +++ b/src/storage_backend_logical.c @@ -594,14 +594,13 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, /* A target path passed to CreateVol has no meaning */ VIR_FREE(vol->target.path); } - if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + - 1 + strlen(vol->name) + 1) < 0) { + + if (virAsprintf(&vol->target.path, "%s/%s", + pool->def->target.path, + vol->name) == -1) { virReportOOMError(conn); return -1; } - strcpy(vol->target.path, pool->def->target.path); - strcat(vol->target.path, "/"); - strcat(vol->target.path, vol->name); if (virRun(conn, cmdargv, NULL) < 0) return -1; diff --git a/src/test.c b/src/test.c index d0e7ae83da..9a9992f775 100644 --- a/src/test.c +++ b/src/test.c @@ -3110,16 +3110,13 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool, goto cleanup; } - if (VIR_ALLOC_N(privvol->target.path, - strlen(privpool->def->target.path) + - 1 + strlen(privvol->name) + 1) < 0) { + if (virAsprintf(&privvol->target.path, "%s/%s", + privpool->def->target.path, + privvol->name) == -1) { virReportOOMError(pool->conn); goto cleanup; } - strcpy(privvol->target.path, privpool->def->target.path); - strcat(privvol->target.path, "/"); - strcat(privvol->target.path, privvol->name); privvol->key = strdup(privvol->target.path); if (privvol->key == NULL) { virReportOOMError(pool->conn); @@ -3204,16 +3201,13 @@ testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - if (VIR_ALLOC_N(privvol->target.path, - strlen(privpool->def->target.path) + - 1 + strlen(privvol->name) + 1) < 0) { + if (virAsprintf(&privvol->target.path, "%s/%s", + privpool->def->target.path, + privvol->name) == -1) { virReportOOMError(pool->conn); goto cleanup; } - strcpy(privvol->target.path, privpool->def->target.path); - strcat(privvol->target.path, "/"); - strcat(privvol->target.path, privvol->name); privvol->key = strdup(privvol->target.path); if (privvol->key == NULL) { virReportOOMError(pool->conn);