From: "John W. Linville" <linville@tuxdriver.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] rte_eth_af_packet: refactor error handling to avoid NULL pointer dereference
Date: Thu, 27 Aug 2015 13:17:13 -0400 [thread overview]
Message-ID: <1440695833-28778-1-git-send-email-linville@tuxdriver.com> (raw)
Coverity CID # 13321
Checking *internals != NULL before accessing req is not good enough,
because **internals is a function argument and the function doesn't
really know what is passed-in. We can close our eyes and ignore the
warning on the basis of controlling all the calling code, or we can
refactor the error exit to avoid the issue entirely...
Signed-off-by: John W. Linville <linville@tuxdriver.com>
---
drivers/net/af_packet/rte_eth_af_packet.c | 44 +++++++++++++++----------------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index bdd9628674cb..cac26e533813 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -454,7 +454,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: no interface specified for AF_PACKET ethdev\n",
name);
- goto error;
+ goto error_early;
}
RTE_LOG(INFO, PMD,
@@ -467,16 +467,16 @@ rte_pmd_init_internals(const char *name,
*/
data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
if (data == NULL)
- goto error;
+ goto error_early;
pci_dev = rte_zmalloc_socket(name, sizeof(*pci_dev), 0, numa_node);
if (pci_dev == NULL)
- goto error;
+ goto error_early;
*internals = rte_zmalloc_socket(name, sizeof(**internals),
0, numa_node);
if (*internals == NULL)
- goto error;
+ goto error_early;
for (q = 0; q < nb_queues; q++) {
(*internals)->rx_queue[q].map = MAP_FAILED;
@@ -498,13 +498,13 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: I/F name too long (%s)\n",
name, pair->value);
- goto error;
+ goto error_early;
}
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
RTE_LOG(ERR, PMD,
"%s: ioctl failed (SIOCGIFINDEX)\n",
name);
- goto error;
+ goto error_early;
}
(*internals)->if_index = ifr.ifr_ifindex;
@@ -512,7 +512,7 @@ rte_pmd_init_internals(const char *name,
RTE_LOG(ERR, PMD,
"%s: ioctl failed (SIOCGIFHWADDR)\n",
name);
- goto error;
+ goto error_early;
}
memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
@@ -678,24 +678,22 @@ rte_pmd_init_internals(const char *name,
return 0;
error:
- rte_free(data);
- rte_free(pci_dev);
-
- if (*internals) {
- for (q = 0; q < nb_queues; q++) {
- munmap((*internals)->rx_queue[q].map,
- 2 * req->tp_block_size * req->tp_block_nr);
-
- rte_free((*internals)->rx_queue[q].rd);
- rte_free((*internals)->tx_queue[q].rd);
- if (((*internals)->rx_queue[q].sockfd != 0) &&
- ((*internals)->rx_queue[q].sockfd != qsockfd))
- close((*internals)->rx_queue[q].sockfd);
- }
- rte_free(*internals);
- }
if (qsockfd != -1)
close(qsockfd);
+ for (q = 0; q < nb_queues; q++) {
+ munmap((*internals)->rx_queue[q].map,
+ 2 * req->tp_block_size * req->tp_block_nr);
+
+ rte_free((*internals)->rx_queue[q].rd);
+ rte_free((*internals)->tx_queue[q].rd);
+ if (((*internals)->rx_queue[q].sockfd != 0) &&
+ ((*internals)->rx_queue[q].sockfd != qsockfd))
+ close((*internals)->rx_queue[q].sockfd);
+ }
+ rte_free(*internals);
+error_early:
+ rte_free(pci_dev);
+ rte_free(data);
return -1;
}
--
2.4.3
next reply other threads:[~2015-08-27 17:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 17:17 John W. Linville [this message]
2015-08-28 10:27 ` Neil Horman
2015-10-20 16:02 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440695833-28778-1-git-send-email-linville@tuxdriver.com \
--to=linville@tuxdriver.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).