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 <reshma.pattan at intel.com>
... > /* 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?