mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
xenParseXLUSB: Rewrite to avoid virStrncpy
Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
207a9db8eb
commit
08372887ec
@ -960,14 +960,10 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
|
|||||||
if (list && list->type == VIR_CONF_LIST) {
|
if (list && list->type == VIR_CONF_LIST) {
|
||||||
list = list->list;
|
list = list->list;
|
||||||
while (list) {
|
while (list) {
|
||||||
char bus[3];
|
|
||||||
char device[3];
|
|
||||||
char *key;
|
char *key;
|
||||||
int busNum;
|
int busNum;
|
||||||
int devNum;
|
int devNum;
|
||||||
|
|
||||||
bus[0] = device[0] = '\0';
|
|
||||||
|
|
||||||
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
|
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
|
||||||
goto skipusb;
|
goto skipusb;
|
||||||
/* usbdev=['hostbus=1,hostaddr=3'] */
|
/* usbdev=['hostbus=1,hostaddr=3'] */
|
||||||
@ -982,20 +978,16 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
|
|||||||
|
|
||||||
if (STRPREFIX(key, "hostbus=")) {
|
if (STRPREFIX(key, "hostbus=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
if (virStrncpy(bus, data, len, sizeof(bus)) < 0) {
|
g_autofree char *tmp = g_strndup(data, len);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("bus %s too big for destination"),
|
if (virStrToLong_i(tmp, NULL, 16, &busNum) < 0)
|
||||||
data);
|
|
||||||
goto skipusb;
|
goto skipusb;
|
||||||
}
|
|
||||||
} else if (STRPREFIX(key, "hostaddr=")) {
|
} else if (STRPREFIX(key, "hostaddr=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
if (virStrncpy(device, data, len, sizeof(device)) < 0) {
|
g_autofree char *tmp = g_strndup(data, len);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("device %s too big for destination"),
|
if (virStrToLong_i(tmp, NULL, 16, &devNum) < 0)
|
||||||
data);
|
|
||||||
goto skipusb;
|
goto skipusb;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nextkey && (nextkey[0] == ',' ||
|
while (nextkey && (nextkey[0] == ',' ||
|
||||||
@ -1005,10 +997,6 @@ xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
|
|||||||
key = nextkey;
|
key = nextkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStrToLong_i(bus, NULL, 16, &busNum) < 0)
|
|
||||||
goto skipusb;
|
|
||||||
if (virStrToLong_i(device, NULL, 16, &devNum) < 0)
|
|
||||||
goto skipusb;
|
|
||||||
if (!(hostdev = virDomainHostdevDefNew()))
|
if (!(hostdev = virDomainHostdevDefNew()))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user