From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ferruh Yigit Subject: Re: [PATCH 1/3] pdump: check getenv return value Date: Tue, 21 Jun 2016 17:55:59 +0100 Message-ID: <5769719F.4060803@intel.com> References: <1466522285-15023-1-git-send-email-reshma.pattan@intel.com> <1466522285-15023-2-git-send-email-reshma.pattan@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable To: Reshma Pattan , dev@dpdk.org 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) In-Reply-To: <1466522285-15023-2-git-send-email-reshma.pattan@intel.com> 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" 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. >=20 > Coverity issue 127344: return value check > Coverity issue 127347: null pointer dereference >=20 > Fixes: 278f945402c5 ("pdump: add new library for packet capture") > Fixes: 278f945402c5 ("pdump: add new library for packet capture") >=20 > 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 =3D NULL; > @@ -451,8 +451,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enu= m rte_pdump_socktype type) > else if (type =3D=3D RTE_PDUMP_SOCKET_CLIENT && client_socket_dir[0] = !=3D 0) > dir =3D client_socket_dir; > else { > - if (getuid() !=3D 0) > + if (getuid() !=3D 0) { > dir =3D 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?