|
|
247641 |
From da98b8f43c74492c5471439d6ca20c15da5aeb45 Mon Sep 17 00:00:00 2001
|
|
|
247641 |
From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= <vpavlin@redhat.com>
|
|
|
247641 |
Date: Thu, 15 Nov 2012 10:24:02 +0100
|
|
|
247641 |
Subject: [PATCH] CoverityScan update
|
|
|
247641 |
|
|
|
247641 |
Resolves: #873636
|
|
|
247641 |
---
|
|
|
247641 |
src/bios_device.c | 14 +++++++++++---
|
|
|
247641 |
src/eths.c | 2 +-
|
|
|
247641 |
src/pci.c | 38 +++++++++++++++++++++++++++++---------
|
|
|
247641 |
3 files changed, 41 insertions(+), 13 deletions(-)
|
|
|
247641 |
|
|
|
247641 |
diff --git a/src/bios_device.c b/src/bios_device.c
|
|
|
247641 |
index 9e319a3..a8827ec 100644
|
|
|
247641 |
--- a/src/bios_device.c
|
|
|
247641 |
+++ b/src/bios_device.c
|
|
|
247641 |
@@ -359,10 +359,11 @@ extern int addslot(struct libbiosdevname_state *state, int slot);
|
|
|
247641 |
|
|
|
247641 |
/* Fix for RHBZ 816536/757743/756164/: Cards with same PCI but multiple ports
|
|
|
247641 |
* chelsio, mellanox */
|
|
|
247641 |
-static void check_ports(struct libbiosdevname_state *state)
|
|
|
247641 |
+static int check_ports(struct libbiosdevname_state *state)
|
|
|
247641 |
{
|
|
|
247641 |
struct pci_device *dev;
|
|
|
247641 |
struct bios_device *a;
|
|
|
247641 |
+ int slot = 0;
|
|
|
247641 |
|
|
|
247641 |
list_for_each_entry(a, &state->bios_devices, node) {
|
|
|
247641 |
dev = a->pcidev;
|
|
|
247641 |
@@ -370,9 +371,14 @@ static void check_ports(struct libbiosdevname_state *state)
|
|
|
247641 |
continue;
|
|
|
247641 |
if (dev->physical_slot != PHYSICAL_SLOT_UNKNOWN) {
|
|
|
247641 |
a->slot_num = dev->physical_slot;
|
|
|
247641 |
- a->port_num = addslot(state, 0x1000 + dev->physical_slot);
|
|
|
247641 |
+ slot = addslot(state, 0x1000 + dev->physical_slot);
|
|
|
247641 |
+ if (slot<0)
|
|
|
247641 |
+ return slot;
|
|
|
247641 |
+ a->port_num = slot;
|
|
|
247641 |
}
|
|
|
247641 |
}
|
|
|
247641 |
+
|
|
|
247641 |
+ return 0;
|
|
|
247641 |
}
|
|
|
247641 |
|
|
|
247641 |
void * setup_bios_devices(int namingpolicy, const char *prefix)
|
|
|
247641 |
@@ -390,7 +396,9 @@ void * setup_bios_devices(int namingpolicy, const char *prefix)
|
|
|
247641 |
get_eths(state);
|
|
|
247641 |
match_all(state);
|
|
|
247641 |
sort_device_list(state);
|
|
|
247641 |
- check_ports(state);
|
|
|
247641 |
+ rc = check_ports(state);
|
|
|
247641 |
+ if (rc)
|
|
|
247641 |
+ goto out;
|
|
|
247641 |
rc = assign_bios_network_names(state, namingpolicy, prefix);
|
|
|
247641 |
if (rc)
|
|
|
247641 |
goto out;
|
|
|
247641 |
diff --git a/src/eths.c b/src/eths.c
|
|
|
247641 |
index bcd02e1..04db300 100644
|
|
|
247641 |
--- a/src/eths.c
|
|
|
247641 |
+++ b/src/eths.c
|
|
|
247641 |
@@ -40,7 +40,7 @@ static int eths_get_ifindex(const char *devname, int *ifindex)
|
|
|
247641 |
struct ifreq ifr;
|
|
|
247641 |
|
|
|
247641 |
memset(&ifr, 0, sizeof(ifr));
|
|
|
247641 |
- strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
|
|
247641 |
+ strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)-1);
|
|
|
247641 |
|
|
|
247641 |
/* Open control socket. */
|
|
|
247641 |
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
247641 |
@@ -63,7 +63,7 @@ static int eths_get_hwaddr(const char *devname, unsigned char *buf, int size, in
|
|
|
247641 |
struct ifreq ifr;
|
|
|
247641 |
|
|
|
247641 |
memset(&ifr, 0, sizeof(ifr));
|
|
|
247641 |
- strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
|
|
247641 |
+ strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)-1);
|
|
|
247641 |
|
|
|
247641 |
/* Open control socket. */
|
|
|
247641 |
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
247641 |
@@ -88,7 +88,7 @@ static int eths_get_info(const char *devname, struct ethtool_drvinfo *drvinfo)
|
|
|
247641 |
|
|
|
247641 |
/* Setup our control structures. */
|
|
|
247641 |
memset(&ifr, 0, sizeof(ifr));
|
|
|
247641 |
- strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
|
|
247641 |
+ strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)-1);
|
|
|
247641 |
|
|
|
247641 |
/* Open control socket. */
|
|
|
247641 |
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
247641 |
@@ -118,7 +118,7 @@ static int eths_get_permaddr(const char *devname, unsigned char *buf, int size)
|
|
|
247641 |
|
|
|
247641 |
/* Setup our control structures. */
|
|
|
247641 |
memset(&ifr, 0, sizeof(ifr));
|
|
|
247641 |
- strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
|
|
|
247641 |
+ strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)-1);
|
|
|
247641 |
|
|
|
247641 |
|
|
|
247641 |
|
|
|
247641 |
diff --git a/src/pci.c b/src/pci.c
|
|
|
247641 |
index 75cf786..9bc0535 100644
|
|
|
247641 |
--- a/src/pci.c
|
|
|
247641 |
+++ b/src/pci.c
|
|
|
247641 |
@@ -198,10 +198,14 @@ static void set_pci_vpd_instance(struct libbiosdevname_state *state)
|
|
|
247641 |
|
|
|
247641 |
/* Read VPD-R on Dell systems only */
|
|
|
247641 |
if ((fd = open("/sys/devices/virtual/dmi/id/sys_vendor", O_RDONLY)) >= 0) {
|
|
|
247641 |
- if (read(fd, sys_vendor, 9) != 9)
|
|
|
247641 |
+ if (read(fd, sys_vendor, 9) != 9) {
|
|
|
247641 |
+ close(fd);
|
|
|
247641 |
return;
|
|
|
247641 |
- if (strncmp(sys_vendor, "Dell Inc.", 9))
|
|
|
247641 |
+ }
|
|
|
247641 |
+ if (strncmp(sys_vendor, "Dell Inc.", 9)) {
|
|
|
247641 |
+ close(fd);
|
|
|
247641 |
return;
|
|
|
247641 |
+ }
|
|
|
247641 |
} else
|
|
|
247641 |
return;
|
|
|
247641 |
|
|
|
247641 |
@@ -238,6 +242,8 @@ static void set_pci_vpd_instance(struct libbiosdevname_state *state)
|
|
|
247641 |
dev->vpd_pf = NULL;
|
|
|
247641 |
}
|
|
|
247641 |
}
|
|
|
247641 |
+
|
|
|
247641 |
+ close(fd);
|
|
|
247641 |
}
|
|
|
247641 |
|
|
|
247641 |
static int pci_find_capability(struct pci_dev *p, int cap)
|
|
|
247641 |
@@ -628,6 +634,8 @@ int addslot(struct libbiosdevname_state *state, int slot)
|
|
|
247641 |
}
|
|
|
247641 |
}
|
|
|
247641 |
s = malloc(sizeof(*s));
|
|
|
247641 |
+ if(!s)
|
|
|
247641 |
+ return -1;
|
|
|
247641 |
INIT_LIST_HEAD(&s->node);
|
|
|
247641 |
s->slot = slot;
|
|
|
247641 |
s->count = 0;
|
|
|
247641 |
@@ -636,9 +644,10 @@ int addslot(struct libbiosdevname_state *state, int slot)
|
|
|
247641 |
return ++s->count;
|
|
|
247641 |
}
|
|
|
247641 |
|
|
|
247641 |
-static void set_pci_slots(struct libbiosdevname_state *state)
|
|
|
247641 |
+static int set_pci_slots(struct libbiosdevname_state *state)
|
|
|
247641 |
{
|
|
|
247641 |
struct pci_device *dev;
|
|
|
247641 |
+ int slot = 0;
|
|
|
247641 |
|
|
|
247641 |
list_for_each_entry(dev, &state->pci_devices, node) {
|
|
|
247641 |
dev_to_slot(state, dev);
|
|
|
247641 |
@@ -651,11 +660,19 @@ static void set_pci_slots(struct libbiosdevname_state *state)
|
|
|
247641 |
}
|
|
|
247641 |
if (dev->physical_slot == 0) {
|
|
|
247641 |
dev->embedded_index_valid = 1;
|
|
|
247641 |
- dev->embedded_index = addslot(state, 0);
|
|
|
247641 |
+ slot = addslot(state, 0);
|
|
|
247641 |
+ if (slot<0)
|
|
|
247641 |
+ return slot;
|
|
|
247641 |
+ dev->embedded_index = slot;
|
|
|
247641 |
} else if (dev->physical_slot != PHYSICAL_SLOT_UNKNOWN) {
|
|
|
247641 |
- dev->index_in_slot = addslot(state, dev->physical_slot);
|
|
|
247641 |
+ slot = addslot(state, dev->physical_slot);
|
|
|
247641 |
+ if (slot<0)
|
|
|
247641 |
+ return slot;
|
|
|
247641 |
+ dev->index_in_slot = slot;
|
|
|
247641 |
}
|
|
|
247641 |
}
|
|
|
247641 |
+
|
|
|
247641 |
+ return 0;
|
|
|
247641 |
}
|
|
|
247641 |
|
|
|
247641 |
static void set_sriov_pf_vf(struct libbiosdevname_state *state)
|
|
|
247641 |
@@ -737,9 +754,12 @@ int get_pci_devices(struct libbiosdevname_state *state)
|
|
|
247641 |
dmidecode_main(state); /* this will fail on Xen guests, that's OK */
|
|
|
247641 |
sort_device_list(state);
|
|
|
247641 |
set_pci_vpd_instance(state);
|
|
|
247641 |
- set_pci_slots(state);
|
|
|
247641 |
+ rc = set_pci_slots(state);
|
|
|
247641 |
+ if(rc)
|
|
|
247641 |
+ goto out;
|
|
|
247641 |
set_sriov_pf_vf(state);
|
|
|
247641 |
|
|
|
247641 |
+out:
|
|
|
247641 |
return rc;
|
|
|
247641 |
}
|
|
|
247641 |
|
|
|
247641 |
diff --git a/src/read_proc.c b/src/read_proc.c
|
|
|
247641 |
index c89cb6d..eb988e9 100644
|
|
|
247641 |
--- a/src/read_proc.c
|
|
|
247641 |
+++ b/src/read_proc.c
|
|
|
247641 |
@@ -25,7 +25,7 @@ static struct network_device *add_interface(struct libbiosdevname_state *state,
|
|
|
247641 |
return NULL;
|
|
|
247641 |
memset(i, 0, sizeof(*i));
|
|
|
247641 |
INIT_LIST_HEAD(&i->node);
|
|
|
247641 |
- strncpy(i->kernel_name, name, sizeof(i->kernel_name));
|
|
|
247641 |
+ strncpy(i->kernel_name, name, sizeof(i->kernel_name)-1);
|
|
|
247641 |
list_add_tail(&i->node, &state->network_devices);
|
|
|
247641 |
return i;
|
|
|
247641 |
}
|
|
|
247641 |
--
|
|
|
247641 |
1.7.11.7
|
|
|
247641 |
|