mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
virDomainDiskDefAssignAddress: return int, not void
Before, this function would blindly accept an invalid def->dst and then abuse the idx=-1 it would get from virDiskNameToIndex, when passing it invalid strings like "xvda:disk" and "sda1". Now, this function returns -1 upon failure. * src/conf/domain_conf.c (virDomainDiskDefAssignAddress): as above. Update callers. * src/conf/domain_conf.h: Update prototype. * src/qemu/qemu_conf.c: Update callers.
This commit is contained in:
parent
67904847f0
commit
c390bcfec5
@ -1233,10 +1233,12 @@ cleanup:
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
int
|
||||
virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
|
||||
{
|
||||
int idx = virDiskNameToIndex(def->dst);
|
||||
if (idx < 0)
|
||||
return -1;
|
||||
|
||||
switch (def->bus) {
|
||||
case VIR_DOMAIN_DISK_BUS_SCSI:
|
||||
@ -1270,6 +1272,8 @@ virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
|
||||
/* Other disk bus's aren't controller based */
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse the XML definition for a disk
|
||||
@ -1498,8 +1502,9 @@ virDomainDiskDefParseXML(xmlNodePtr node,
|
||||
def->serial = serial;
|
||||
serial = NULL;
|
||||
|
||||
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
|
||||
virDomainDiskDefAssignAddress(def);
|
||||
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE
|
||||
&& virDomainDiskDefAssignAddress(def) < 0)
|
||||
goto error;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(bus);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* domain_conf.h: domain XML processing
|
||||
*
|
||||
* Copyright (C) 2006-2008 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008, 2010 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -855,7 +855,7 @@ int virDomainDiskInsert(virDomainDefPtr def,
|
||||
virDomainDiskDefPtr disk);
|
||||
void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
|
||||
virDomainDiskDefPtr disk);
|
||||
void virDomainDiskDefAssignAddress(virDomainDiskDefPtr def);
|
||||
int virDomainDiskDefAssignAddress(virDomainDiskDefPtr def);
|
||||
|
||||
int virDomainControllerInsert(virDomainDefPtr def,
|
||||
virDomainControllerDefPtr controller);
|
||||
|
@ -4815,7 +4815,13 @@ qemuParseCommandLineDisk(const char *val,
|
||||
else
|
||||
def->dst[2] = 'a' + idx;
|
||||
|
||||
virDomainDiskDefAssignAddress(def);
|
||||
if (virDomainDiskDefAssignAddress(def) < 0) {
|
||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("invalid device name '%s'"), def->dst);
|
||||
virDomainDiskDefFree(def);
|
||||
def = NULL;
|
||||
/* fall through to "cleanup" */
|
||||
}
|
||||
|
||||
cleanup:
|
||||
for (i = 0 ; i < nkeywords ; i++) {
|
||||
@ -5623,7 +5629,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
virDomainDiskDefAssignAddress(disk);
|
||||
if (virDomainDiskDefAssignAddress(disk) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
|
||||
virDomainDiskDefFree(disk);
|
||||
|
Loading…
Reference in New Issue
Block a user