mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-02 04:15:46 +00:00
src: Initialize stack allocated virPCIDeviceAddress variables
There are few places where a virPCIDeviceAddress typed variable is allocated on the stack but it's not initialized. This can lead to random values of its members which in turn can lead to a random behaviour. Generated with help of the following spatch: @@ identifier I; @@ - virPCIDeviceAddress I; + virPCIDeviceAddress I = { 0 }; And then fixing bhyveAssignDevicePCISlots() which does declare the variable and then explicitly zero it by calling memset() only to set a specific member afterwards. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
9a98ad6ddb
commit
1c7c759f5b
@ -83,10 +83,7 @@ bhyveAssignDevicePCISlots(virDomainDef *def,
|
|||||||
virDomainPCIAddressSet *addrs)
|
virDomainPCIAddressSet *addrs)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
virPCIDeviceAddress lpc_addr;
|
virPCIDeviceAddress lpc_addr = { .slot = 0x1 };
|
||||||
|
|
||||||
memset(&lpc_addr, 0, sizeof(lpc_addr));
|
|
||||||
lpc_addr.slot = 0x1;
|
|
||||||
|
|
||||||
/* If the user didn't explicitly specify slot 1 for some of the devices,
|
/* If the user didn't explicitly specify slot 1 for some of the devices,
|
||||||
reserve it for LPC, even if there's no LPC device configured.
|
reserve it for LPC, even if there's no LPC device configured.
|
||||||
|
@ -1181,7 +1181,7 @@ virDomainPCIAddressReserveNextAddr(virDomainPCIAddressSet *addrs,
|
|||||||
virDomainPCIConnectFlags flags,
|
virDomainPCIConnectFlags flags,
|
||||||
int function)
|
int function)
|
||||||
{
|
{
|
||||||
virPCIDeviceAddress addr;
|
virPCIDeviceAddress addr = { 0 };
|
||||||
|
|
||||||
if (virDomainPCIAddressGetNextAddr(addrs, &addr, flags,
|
if (virDomainPCIAddressGetNextAddr(addrs, &addr, flags,
|
||||||
dev->isolationGroup, function) < 0)
|
dev->isolationGroup, function) < 0)
|
||||||
|
@ -2947,7 +2947,7 @@ virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDev *pci_dev)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int tmpGroup;
|
int tmpGroup;
|
||||||
virPCIDeviceAddress addr;
|
virPCIDeviceAddress addr = { 0 };
|
||||||
|
|
||||||
/* this could be a refresh, so clear out the old data */
|
/* this could be a refresh, so clear out the old data */
|
||||||
for (i = 0; i < pci_dev->nIommuGroupDevices; i++)
|
for (i = 0; i < pci_dev->nIommuGroupDevices; i++)
|
||||||
@ -3018,7 +3018,7 @@ static int
|
|||||||
virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev *devCapPCIDev)
|
virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev *devCapPCIDev)
|
||||||
{
|
{
|
||||||
g_autoptr(virPCIDevice) pciDev = NULL;
|
g_autoptr(virPCIDevice) pciDev = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr = { 0 };
|
||||||
g_autoptr(virPCIVPDResource) res = NULL;
|
g_autoptr(virPCIVPDResource) res = NULL;
|
||||||
|
|
||||||
devAddr.domain = devCapPCIDev->domain;
|
devAddr.domain = devCapPCIDev->domain;
|
||||||
|
@ -375,7 +375,7 @@ virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
|
|||||||
virHostdevManager *hostdevMgr)
|
virHostdevManager *hostdevMgr)
|
||||||
{
|
{
|
||||||
g_autoptr(virPCIDevice) pci = NULL;
|
g_autoptr(virPCIDevice) pci = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr = { 0 };
|
||||||
g_autoptr(virNodeDeviceDef) def = NULL;
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
||||||
g_autofree char *xml = NULL;
|
g_autofree char *xml = NULL;
|
||||||
g_autoptr(virConnect) nodeconn = NULL;
|
g_autoptr(virConnect) nodeconn = NULL;
|
||||||
@ -421,7 +421,7 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev,
|
|||||||
virHostdevManager *hostdevMgr)
|
virHostdevManager *hostdevMgr)
|
||||||
{
|
{
|
||||||
g_autoptr(virPCIDevice) pci = NULL;
|
g_autoptr(virPCIDevice) pci = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr = { 0 };
|
||||||
g_autoptr(virNodeDeviceDef) def = NULL;
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
||||||
g_autofree char *xml = NULL;
|
g_autofree char *xml = NULL;
|
||||||
g_autoptr(virConnect) nodeconn = NULL;
|
g_autoptr(virConnect) nodeconn = NULL;
|
||||||
@ -466,7 +466,7 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
|||||||
const char *driverName)
|
const char *driverName)
|
||||||
{
|
{
|
||||||
g_autoptr(virPCIDevice) pci = NULL;
|
g_autoptr(virPCIDevice) pci = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr = { 0 };
|
||||||
g_autoptr(virNodeDeviceDef) def = NULL;
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
||||||
g_autofree char *xml = NULL;
|
g_autofree char *xml = NULL;
|
||||||
g_autoptr(virConnect) nodeconn = NULL;
|
g_autoptr(virConnect) nodeconn = NULL;
|
||||||
|
@ -366,7 +366,7 @@ udevProcessPCI(struct udev_device *device,
|
|||||||
virNodeDevCapPCIDev *pci_dev = &def->caps->data.pci_dev;
|
virNodeDevCapPCIDev *pci_dev = &def->caps->data.pci_dev;
|
||||||
virPCIEDeviceInfo *pci_express = NULL;
|
virPCIEDeviceInfo *pci_express = NULL;
|
||||||
virPCIDevice *pciDev = NULL;
|
virPCIDevice *pciDev = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr = { 0 };
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *p;
|
char *p;
|
||||||
bool privileged = false;
|
bool privileged = false;
|
||||||
|
@ -1743,7 +1743,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDef *def,
|
|||||||
virDomainPCIAddressSet *addrs)
|
virDomainPCIAddressSet *addrs)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
virPCIDeviceAddress tmp_addr;
|
virPCIDeviceAddress tmp_addr = { 0 };
|
||||||
g_autofree char *addrStr = NULL;
|
g_autofree char *addrStr = NULL;
|
||||||
virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_AUTOASSIGN
|
virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_AUTOASSIGN
|
||||||
| VIR_PCI_CONNECT_TYPE_PCI_DEVICE);
|
| VIR_PCI_CONNECT_TYPE_PCI_DEVICE);
|
||||||
@ -1853,7 +1853,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDef *def,
|
|||||||
virDomainPCIAddressSet *addrs)
|
virDomainPCIAddressSet *addrs)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
virPCIDeviceAddress tmp_addr;
|
virPCIDeviceAddress tmp_addr = { 0 };
|
||||||
g_autofree char *addrStr = NULL;
|
g_autofree char *addrStr = NULL;
|
||||||
virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCIE_DEVICE;
|
virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPE_PCIE_DEVICE;
|
||||||
|
|
||||||
|
@ -1865,7 +1865,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddress *orig,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((direrr = virDirRead(groupDir, &ent, groupPath)) > 0) {
|
while ((direrr = virDirRead(groupDir, &ent, groupPath)) > 0) {
|
||||||
virPCIDeviceAddress newDev;
|
virPCIDeviceAddress newDev = { 0 };
|
||||||
|
|
||||||
if (virPCIDeviceAddressParse(ent->d_name, &newDev) < 0) {
|
if (virPCIDeviceAddressParse(ent->d_name, &newDev) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
Loading…
Reference in New Issue
Block a user