From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: Reshma Pattan <reshma.pattan@intel.com>
Subject: [dpdk-dev] [PATCH v4 2/5] pdump: check getenv return value
Date: Fri, 24 Jun 2016 14:54:30 +0100 [thread overview]
Message-ID: <1466776473-30883-3-git-send-email-reshma.pattan@intel.com> (raw)
In-Reply-To: <1466776473-30883-1-git-send-email-reshma.pattan@intel.com>
inside pdump_get_socket_path(), getenv can return
a NULL pointer if the match for SOCKET_PATH_HOME is
not found in the environment. NULL check is added to
return -1 immediately. Since pdump_get_socket_path()
returns -1 now, wherever this function is called
there the return value is checked and error message
is logged.
Coverity issue 127344: return value check
Coverity issue 127347: null pointer dereference
Fixes: 278f945402c5 ("pdump: add new library for packet capture")
Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
lib/librte_pdump/rte_pdump.c | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c
index 5c335ba..8240387 100644
--- a/lib/librte_pdump/rte_pdump.c
+++ b/lib/librte_pdump/rte_pdump.c
@@ -442,7 +442,7 @@ set_pdump_rxtx_cbs(struct pdump_request *p)
}
/* get socket path (/var/run if root, $HOME otherwise) */
-static void
+static int
pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
{
char dir[PATH_MAX] = {0};
@@ -455,9 +455,17 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
else {
if (getuid() != 0) {
dir_home = getenv(SOCKET_PATH_HOME);
+ if (!dir_home) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to get environment variable"
+ " value for %s, %s:%d\n",
+ SOCKET_PATH_HOME, __func__, __LINE__);
+ return -1;
+ }
strcat(dir, dir_home);
} else
strcat(dir, SOCKET_PATH_VAR_RUN);
+
strcat(dir, SOCKET_DIR);
}
@@ -467,6 +475,8 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
else
snprintf(buffer, bufsz, CLIENT_SOCKET, dir, getpid(),
rte_sys_gettid());
+
+ return 0;
}
static int
@@ -476,8 +486,14 @@ pdump_create_server_socket(void)
struct sockaddr_un addr;
socklen_t addr_len;
- pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ ret = pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
RTE_PDUMP_SOCKET_SERVER);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to get server socket path: %s:%d\n",
+ __func__, __LINE__);
+ return -1;
+ }
addr.sun_family = AF_UNIX;
/* remove if file already exists */
@@ -608,8 +624,14 @@ rte_pdump_uninit(void)
struct sockaddr_un addr;
- pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ ret = pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
RTE_PDUMP_SOCKET_SERVER);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to get server socket path: %s:%d\n",
+ __func__, __LINE__);
+ return -1;
+ }
ret = unlink(addr.sun_path);
if (ret != 0) {
RTE_LOG(ERR, PDUMP,
@@ -643,8 +665,14 @@ pdump_create_client_socket(struct pdump_request *p)
return ret;
}
- pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
+ ret = pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
RTE_PDUMP_SOCKET_CLIENT);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to get client socket path: %s:%d\n",
+ __func__, __LINE__);
+ return -1;
+ }
addr.sun_family = AF_UNIX;
addr_len = sizeof(struct sockaddr_un);
@@ -660,9 +688,15 @@ pdump_create_client_socket(struct pdump_request *p)
serv_len = sizeof(struct sockaddr_un);
memset(&serv_addr, 0, sizeof(serv_addr));
- pdump_get_socket_path(serv_addr.sun_path,
+ ret = pdump_get_socket_path(serv_addr.sun_path,
sizeof(serv_addr.sun_path),
RTE_PDUMP_SOCKET_SERVER);
+ if (ret != 0) {
+ RTE_LOG(ERR, PDUMP,
+ "Failed to get server socket path: %s:%d\n",
+ __func__, __LINE__);
+ break;
+ }
serv_addr.sun_family = AF_UNIX;
n = sendto(socket_fd, p, sizeof(struct pdump_request), 0,
--
2.5.0
next prev parent reply other threads:[~2016-06-24 13:54 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-21 15:18 [dpdk-dev] [PATCH 0/3] fix coverity issues in packet capture framework Reshma Pattan
2016-06-21 15:18 ` [dpdk-dev] [PATCH 1/3] pdump: check getenv return value Reshma Pattan
2016-06-21 16:55 ` Ferruh Yigit
2016-06-22 8:01 ` Pattan, Reshma
2016-06-21 15:18 ` [dpdk-dev] [PATCH 2/3] pdump: fix string overflow Reshma Pattan
2016-06-21 17:14 ` Ferruh Yigit
2016-06-21 15:18 ` [dpdk-dev] [PATCH 3/3] app/pdump: " Reshma Pattan
2016-06-21 17:21 ` Ferruh Yigit
2016-06-22 6:46 ` Anupam Kapoor
2016-06-22 9:21 ` Bruce Richardson
2016-06-22 9:24 ` Pattan, Reshma
2016-06-22 14:07 ` [dpdk-dev] [PATCH v2 0/3] fix coverity issues in packet capture framework Reshma Pattan
2016-06-22 14:07 ` [dpdk-dev] [PATCH v2 1/3] pdump: check getenv return value Reshma Pattan
2016-06-22 14:07 ` [dpdk-dev] [PATCH v2 2/3] pdump: fix string overflow Reshma Pattan
2016-06-22 14:07 ` [dpdk-dev] [PATCH v2 3/3] app/pdump: " Reshma Pattan
2016-06-23 14:36 ` [dpdk-dev] [PATCH v3 0/4] fix issues in packet capture framework Reshma Pattan
2016-06-23 14:36 ` [dpdk-dev] [PATCH v3 1/4] pdump: fix default socket path Reshma Pattan
2016-06-23 14:36 ` [dpdk-dev] [PATCH v3 2/4] pdump: check getenv return value Reshma Pattan
2016-06-23 14:36 ` [dpdk-dev] [PATCH v3 3/4] pdump: fix string overflow Reshma Pattan
2016-06-23 14:36 ` [dpdk-dev] [PATCH v3 4/4] app/pdump: " Reshma Pattan
2016-06-24 13:54 ` [dpdk-dev] [PATCH v4 0/5] fix issues in packet capture framework Reshma Pattan
2016-06-24 13:54 ` [dpdk-dev] [PATCH v4 1/5] pdump: fix default socket path Reshma Pattan
2016-06-24 14:54 ` Thomas Monjalon
2016-06-24 15:05 ` Pattan, Reshma
2016-06-24 16:39 ` Pattan, Reshma
2016-06-24 13:54 ` Reshma Pattan [this message]
2016-06-24 13:54 ` [dpdk-dev] [PATCH v4 3/5] pdump: fix string overflow Reshma Pattan
2016-06-24 13:54 ` [dpdk-dev] [PATCH v4 4/5] app/pdump: " Reshma Pattan
2016-06-24 13:54 ` [dpdk-dev] [PATCH v4 5/5] app/pdump: fix type casting of ring size Reshma Pattan
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 0/5] fix issues in packet capture framework Reshma Pattan
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 1/5] pdump: fix default socket path Reshma Pattan
2016-06-24 22:50 ` Mcnamara, John
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 2/5] pdump: check getenv return value Reshma Pattan
2016-06-24 22:50 ` Mcnamara, John
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 3/5] pdump: fix string overflow Reshma Pattan
2016-06-24 22:51 ` Mcnamara, John
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 4/5] app/pdump: " Reshma Pattan
2016-06-24 22:51 ` Mcnamara, John
2016-06-24 16:36 ` [dpdk-dev] [PATCH v5 5/5] app/pdump: fix type casting of ring size Reshma Pattan
2016-06-24 22:51 ` Mcnamara, John
2016-06-27 14:50 ` [dpdk-dev] [PATCH v5 0/5] fix issues in packet capture framework 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=1466776473-30883-3-git-send-email-reshma.pattan@intel.com \
--to=reshma.pattan@intel.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).