提交 c390bcfe 编写于 作者: J Jim Meyering

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.
上级 67904847
...@@ -1233,10 +1233,12 @@ cleanup: ...@@ -1233,10 +1233,12 @@ cleanup:
} }
void int
virDomainDiskDefAssignAddress(virDomainDiskDefPtr def) virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
{ {
int idx = virDiskNameToIndex(def->dst); int idx = virDiskNameToIndex(def->dst);
if (idx < 0)
return -1;
switch (def->bus) { switch (def->bus) {
case VIR_DOMAIN_DISK_BUS_SCSI: case VIR_DOMAIN_DISK_BUS_SCSI:
...@@ -1270,6 +1272,8 @@ virDomainDiskDefAssignAddress(virDomainDiskDefPtr def) ...@@ -1270,6 +1272,8 @@ virDomainDiskDefAssignAddress(virDomainDiskDefPtr def)
/* Other disk bus's aren't controller based */ /* Other disk bus's aren't controller based */
break; break;
} }
return 0;
} }
/* Parse the XML definition for a disk /* Parse the XML definition for a disk
...@@ -1498,8 +1502,9 @@ virDomainDiskDefParseXML(xmlNodePtr node, ...@@ -1498,8 +1502,9 @@ virDomainDiskDefParseXML(xmlNodePtr node,
def->serial = serial; def->serial = serial;
serial = NULL; serial = NULL;
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE
virDomainDiskDefAssignAddress(def); && virDomainDiskDefAssignAddress(def) < 0)
goto error;
cleanup: cleanup:
VIR_FREE(bus); VIR_FREE(bus);
......
/* /*
* domain_conf.h: domain XML processing * 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 * Copyright (C) 2006-2008 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -855,7 +855,7 @@ int virDomainDiskInsert(virDomainDefPtr def, ...@@ -855,7 +855,7 @@ int virDomainDiskInsert(virDomainDefPtr def,
virDomainDiskDefPtr disk); virDomainDiskDefPtr disk);
void virDomainDiskInsertPreAlloced(virDomainDefPtr def, void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
virDomainDiskDefPtr disk); virDomainDiskDefPtr disk);
void virDomainDiskDefAssignAddress(virDomainDiskDefPtr def); int virDomainDiskDefAssignAddress(virDomainDiskDefPtr def);
int virDomainControllerInsert(virDomainDefPtr def, int virDomainControllerInsert(virDomainDefPtr def,
virDomainControllerDefPtr controller); virDomainControllerDefPtr controller);
......
...@@ -4815,7 +4815,13 @@ qemuParseCommandLineDisk(const char *val, ...@@ -4815,7 +4815,13 @@ qemuParseCommandLineDisk(const char *val,
else else
def->dst[2] = 'a' + idx; 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: cleanup:
for (i = 0 ; i < nkeywords ; i++) { for (i = 0 ; i < nkeywords ; i++) {
...@@ -5623,7 +5629,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps, ...@@ -5623,7 +5629,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
goto no_memory; goto no_memory;
} }
virDomainDiskDefAssignAddress(disk); if (virDomainDiskDefAssignAddress(disk) < 0)
goto error;
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册