From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 94266C420 for ; Tue, 21 Jun 2016 18:56:01 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 21 Jun 2016 09:56:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,505,1459839600"; d="scan'208";a="832550892" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.90]) ([10.237.220.90]) by orsmga003.jf.intel.com with ESMTP; 21 Jun 2016 09:55:59 -0700 To: Reshma Pattan , dev@dpdk.org References: <1466522285-15023-1-git-send-email-reshma.pattan@intel.com> <1466522285-15023-2-git-send-email-reshma.pattan@intel.com> From: Ferruh Yigit Message-ID: <5769719F.4060803@intel.com> Date: Tue, 21 Jun 2016 17:55:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <1466522285-15023-2-git-send-email-reshma.pattan@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [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: , X-List-Received-Date: Tue, 21 Jun 2016 16:56:02 -0000 On 6/21/2016 4:18 PM, Reshma Pattan wrote: > 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 ... > /* 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; Instead of failing, does it make sense to fallback to a default path? Is it possible that sometimes end user doesn't really care where socket created as long as it created and runs smoothly?