Use virAsprintf, rather than VIR_ALLOC + strcpy + strcat

This commit is contained in:
Cole Robinson 2009-05-19 13:15:50 +00:00
parent bb175dfc53
commit adf4384501
7 changed files with 39 additions and 49 deletions

View File

@ -1,3 +1,10 @@
Tue May 19 09:14:12 EDT 2009 Cole Robinson <crobinso@redhat.com>
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 <crobinso@redhat.com> Tue May 19 09:04:05 EDT 2009 Cole Robinson <crobinso@redhat.com>
* src/virsh.c: Don't validate disk type in virsh attach-disk * src/virsh.c: Don't validate disk type in virsh attach-disk

View File

@ -52,7 +52,9 @@
#include "datatypes.h" #include "datatypes.h"
#include "qemud.h" #include "qemud.h"
#include "memory.h" #include "memory.h"
#include "util.h"
#define VIR_FROM_THIS VIR_FROM_REMOTE
#define REMOTE_DEBUG(fmt, ...) DEBUG(fmt, __VA_ARGS__) #define REMOTE_DEBUG(fmt, ...) DEBUG(fmt, __VA_ARGS__)
static void remoteDispatchFormatError (remote_error *rerr, static void remoteDispatchFormatError (remote_error *rerr,
@ -2602,14 +2604,11 @@ static char *addrToString(remote_error *rerr,
return NULL; return NULL;
} }
if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) { if (virAsprintf(&addr, "%s;%s", host, port) == -1) {
remoteDispatchOOMError(rerr); virReportOOMError(NULL);
return NULL; return NULL;
} }
strcpy(addr, host);
strcat(addr, ";");
strcat(addr, port);
return addr; return addr;
} }

View File

@ -5189,14 +5189,11 @@ static char *addrToString(struct sockaddr_storage *sa, socklen_t salen)
return NULL; return NULL;
} }
if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) { if (virAsprintf(&addr, "%s;%s", host, port) == -1) {
virReportOOMError (NULL); virReportOOMError(NULL);
return NULL; return NULL;
} }
strcpy(addr, host);
strcat(addr, ";");
strcat(addr, port);
return addr; return addr;
} }

View File

@ -342,17 +342,14 @@ virStorageBackendStablePath(virConnectPtr conn,
if (dent->d_name[0] == '.') if (dent->d_name[0] == '.')
continue; continue;
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) + if (virAsprintf(&stablepath, "%s/%s",
1 + strlen(dent->d_name) + 1) < 0) { pool->def->target.path,
dent->d_name) == -1) {
virReportOOMError(conn); virReportOOMError(conn);
closedir(dh); closedir(dh);
return NULL; return NULL;
} }
strcpy(stablepath, pool->def->target.path);
strcat(stablepath, "/");
strcat(stablepath, dent->d_name);
if (virFileLinkPointsTo(stablepath, devpath)) { if (virFileLinkPointsTo(stablepath, devpath)) {
closedir(dh); closedir(dh);
return stablepath; return stablepath;

View File

@ -668,14 +668,13 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
} }
if (pool->def->type == VIR_STORAGE_POOL_NETFS) { if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) + if (virAsprintf(&src, "%s:%s",
1 + strlen(pool->def->source.dir) + 1) < 0) { pool->def->source.host.name,
pool->def->source.dir) == -1) {
virReportOOMError(conn); virReportOOMError(conn);
return -1; return -1;
} }
strcpy(src, pool->def->source.host.name);
strcat(src, ":");
strcat(src, pool->def->source.dir);
} else { } else {
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) { if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
virReportOOMError(conn); virReportOOMError(conn);
@ -829,13 +828,11 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
vol->type = VIR_STORAGE_VOL_FILE; vol->type = VIR_STORAGE_VOL_FILE;
vol->target.format = VIR_STORAGE_VOL_FILE_RAW; /* Real value is filled in during probe */ 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) + if (virAsprintf(&vol->target.path, "%s/%s",
1 + strlen(vol->name) + 1) < 0) pool->def->target.path,
vol->name) == -1)
goto no_memory; 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) if ((vol->key = strdup(vol->target.path)) == NULL)
goto no_memory; goto no_memory;
@ -995,15 +992,15 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) + vol->type = VIR_STORAGE_VOL_FILE;
1 + strlen(vol->name) + 1) < 0) {
if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path,
vol->name) == -1) {
virReportOOMError(conn); virReportOOMError(conn);
return -1; 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); vol->key = strdup(vol->target.path);
if (vol->key == NULL) { if (vol->key == NULL) {
virReportOOMError(conn); virReportOOMError(conn);

View File

@ -594,14 +594,13 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
/* A target path passed to CreateVol has no meaning */ /* A target path passed to CreateVol has no meaning */
VIR_FREE(vol->target.path); 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); virReportOOMError(conn);
return -1; 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) if (virRun(conn, cmdargv, NULL) < 0)
return -1; return -1;

View File

@ -3110,16 +3110,13 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(privvol->target.path, if (virAsprintf(&privvol->target.path, "%s/%s",
strlen(privpool->def->target.path) + privpool->def->target.path,
1 + strlen(privvol->name) + 1) < 0) { privvol->name) == -1) {
virReportOOMError(pool->conn); virReportOOMError(pool->conn);
goto cleanup; 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); privvol->key = strdup(privvol->target.path);
if (privvol->key == NULL) { if (privvol->key == NULL) {
virReportOOMError(pool->conn); virReportOOMError(pool->conn);
@ -3204,16 +3201,13 @@ testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(privvol->target.path, if (virAsprintf(&privvol->target.path, "%s/%s",
strlen(privpool->def->target.path) + privpool->def->target.path,
1 + strlen(privvol->name) + 1) < 0) { privvol->name) == -1) {
virReportOOMError(pool->conn); virReportOOMError(pool->conn);
goto cleanup; 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); privvol->key = strdup(privvol->target.path);
if (privvol->key == NULL) { if (privvol->key == NULL) {
virReportOOMError(pool->conn); virReportOOMError(pool->conn);