From patchwork Tue Jun 21 15:18:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 14178 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id EB035C3DA; Tue, 21 Jun 2016 17:18:24 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 31E0AC33A for ; Tue, 21 Jun 2016 17:18:22 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 21 Jun 2016 08:18:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.26,504,1459839600"; d="scan'208"; a="1006738169" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 21 Jun 2016 08:18:08 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id u5LFI77x024661; Tue, 21 Jun 2016 16:18:07 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id u5LFI7qi015070; Tue, 21 Jun 2016 16:18:07 +0100 Received: (from reshmapa@localhost) by sivswdev02.ir.intel.com with id u5LFI75X015066; Tue, 21 Jun 2016 16:18:07 +0100 From: Reshma Pattan To: dev@dpdk.org Cc: Reshma Pattan Date: Tue, 21 Jun 2016 16:18:03 +0100 Message-Id: <1466522285-15023-2-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1466522285-15023-1-git-send-email-reshma.pattan@intel.com> References: <1466522285-15023-1-git-send-email-reshma.pattan@intel.com> Subject: [dpdk-dev] [PATCH 1/3] pdump: check getenv return value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 immediately without calling mkdir. Coverity issue 127344: return value check Coverity issue 127347: null pointer dereference Fixes: 278f945402c5 ("pdump: add new library for packet capture") Fixes: 278f945402c5 ("pdump: add new library for packet capture") Signed-off-by: Reshma Pattan --- lib/librte_pdump/rte_pdump.c | 46 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index c921f51..dbc6816 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -441,7 +441,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) { const char *dir = NULL; @@ -451,8 +451,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type) else if (type == RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0] != 0) dir = client_socket_dir; else { - if (getuid() != 0) + if (getuid() != 0) { dir = getenv(SOCKET_PATH_HOME); + if (!dir) { + RTE_LOG(ERR, PDUMP, + "Failed to get environment variable" + "value for %s, %s:%d\n", + SOCKET_PATH_HOME, __func__, __LINE__); + return -1; + } + } else dir = SOCKET_PATH_VAR_RUN; } @@ -463,6 +471,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 @@ -472,8 +482,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 */ @@ -604,8 +620,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, @@ -639,8 +661,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); @@ -656,9 +684,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,