Skip to contentSkip to conversation

(More) Fixes for issues highlighted by static analysis

PATCH Applied Bruce Richardson 2 participants 5 messages Dec 16, 2014 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover (More) Fixes for issues highlighted by static analysis

A further three small patches fixing more issues highlighted by static analysis scans.

Bruce Richardson (3):
af_packet: ensure *internals is not null when dereferencing
ixgbe: prevent array overflow access in vector driver
eal: for safety, use snprintf instead of sprintf

 lib/librte_eal/common/include/rte_version.h  |  4 ++--
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 15 ++++++++-------
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c        |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.3
#2 lore raw

PATCH 1/3 af_packet: ensure *internals is not null when dereferencing

In reply to a message not in the archive

The cleanup code on error checks for *internals being NULL only after using the pointer to perform other cleanup. Fix this by moving the clean-up based on the pointer inside the check for NULL.

---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
lib/librte_pmd_af_packet/rte_eth_af_packet.c +8 -7
index d0fb3eb..ad7242c 100644
@@ -676,14 +676,15 @@ error:
 		rte_free(data);
 	if (pci_dev)
 		rte_free(pci_dev);
-	for (q = 0; q < nb_queues; q++) {
-		if ((*internals)->rx_queue[q].rd)
-			rte_free((*internals)->rx_queue[q].rd);
-		if ((*internals)->tx_queue[q].rd)
-			rte_free((*internals)->tx_queue[q].rd);
-	}
-	if (*internals)
+	if (*internals) {
+		for (q = 0; q < nb_queues; q++) {
+			if ((*internals)->rx_queue[q].rd)
+				rte_free((*internals)->rx_queue[q].rd);
+			if ((*internals)->tx_queue[q].rd)
+				rte_free((*internals)->tx_queue[q].rd);
+		}
 		rte_free(*internals);
+	}
 	return -1;
 }
 
Signature · 1 line
1.9.3
#3 lore raw

PATCH 2/3 ixgbe: prevent array overflow access in vector driver

In reply to a message not in the archive

Switch the order of the conditions in a while loop, so we check the range of "i" against the max, before using it to index into the array.

---
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c +1 -1
index 3a30fa7..b54cb19 100644
@@ -489,7 +489,7 @@ ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
 	unsigned i = 0;
 	if (rxq->pkt_first_seg == NULL) {
 		/* find the first split flag, and only reassemble then*/
-		while (!split_flags[i] && i < nb_bufs)
+		while (i < nb_bufs && !split_flags[i])
 			i++;
 		if (i == nb_bufs)
 			return nb_bufs;
Signature · 1 line
1.9.3
#4 lore raw

PATCH 3/3 eal: for safety, use snprintf instead of sprintf

In reply to a message not in the archive

When printing the version string to a local variable, use snprintf for safety over sprintf. This is general good practice even if the values to print are all hard-coded.

---
 lib/librte_eal/common/include/rte_version.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_eal/common/include/rte_version.h +2 -2
index 54cb9a6..356207c 100644
@@ -104,13 +104,13 @@ rte_version(void)
 	if (version[0] != 0)
 		return version;
 	if (strlen(RTE_VER_SUFFIX) == 0)
-		sprintf(version, "%s %d.%d.%d",
+		snprintf(version, sizeof(version), "%s %d.%d.%d",
 			RTE_VER_PREFIX,
 			RTE_VER_MAJOR,
 			RTE_VER_MINOR,
 			RTE_VER_PATCH_LEVEL);
 	else
-		sprintf(version, "%s %d.%d.%d%s%d",
+		snprintf(version, sizeof(version), "%s %d.%d.%d%s%d",
 			RTE_VER_PREFIX,
 			RTE_VER_MAJOR,
 			RTE_VER_MINOR,
Signature · 1 line
1.9.3
#5 lore raw
In reply to a message not in the archive
Quoted 7 lines

A further three small patches fixing more issues highlighted by static analysis scans.

Bruce Richardson (3):
af_packet: ensure *internals is not null when dereferencing
ixgbe: prevent array overflow access in vector driver
eal: for safety, use snprintf instead of sprintf

Applied

Thanks

Signature · 1 line
Thomas