From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2F2292BB3 for ; Wed, 22 Jun 2016 11:21:34 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 22 Jun 2016 02:21:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,509,1459839600"; d="scan'208";a="723280801" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.220.108]) by FMSMGA003.fm.intel.com with SMTP; 22 Jun 2016 02:21:32 -0700 Received: by (sSMTP sendmail emulation); Wed, 22 Jun 2016 10:21:30 +0025 Date: Wed, 22 Jun 2016 10:21:30 +0100 From: Bruce Richardson To: Anupam Kapoor Cc: Ferruh Yigit , Reshma Pattan , dev@dpdk.org Message-ID: <20160622092130.GB9728@bricha3-MOBL3> References: <1466522285-15023-1-git-send-email-reshma.pattan@intel.com> <1466522285-15023-4-git-send-email-reshma.pattan@intel.com> <57697789.6050500@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Research and =?iso-8859-1?Q?De=ACvel?= =?iso-8859-1?Q?opment?= Ireland Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH 3/3] app/pdump: fix string overflow 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: Wed, 22 Jun 2016 09:21:34 -0000 On Wed, Jun 22, 2016 at 12:16:27PM +0530, Anupam Kapoor wrote: > > if (!strcmp(key, PDUMP_RX_DEV_ARG)) { > > - strncpy(pt->rx_dev, value, strlen(value)); > > + strncpy(pt->rx_dev, value, sizeof(pt->rx_dev)-1); > > I guess size-1 is to give room for terminating null byte, but for this > case is it guarantied that pt->rx_dev last byte is NULL? > > why not just use a snprintf(...) here since it has better error behavior ? > although compared to str*cpy it might be a bit slow, but hopefully that > should be ok ? > Definite +1. For safely copying strings I think snprintf is often the easiest API to use. /Bruce > -- > thanks > anupam > > > On Tue, Jun 21, 2016 at 10:51 PM, Ferruh Yigit > wrote: > > > On 6/21/2016 4:18 PM, Reshma Pattan wrote: > > > using source length in strncpy can cause destination > > > overflow if destination length is not big enough to > > > handle the source string. Changes are made to use destination > > > size instead of source length in strncpy. > > > > > > Coverity issue 127351: string overflow > > > > > > Fixes: caa7028276b8 ("app/pdump: add tool for packet capturing") > > > > > > Signed-off-by: Reshma Pattan > > > --- > > > app/pdump/main.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/app/pdump/main.c b/app/pdump/main.c > > > index f8923b9..af92ef3 100644 > > > --- a/app/pdump/main.c > > > +++ b/app/pdump/main.c > > > @@ -217,12 +217,12 @@ parse_rxtxdev(const char *key, const char *value, > > void *extra_args) > > > struct pdump_tuples *pt = extra_args; > > > > > > if (!strcmp(key, PDUMP_RX_DEV_ARG)) { > > > - strncpy(pt->rx_dev, value, strlen(value)); > > > + strncpy(pt->rx_dev, value, sizeof(pt->rx_dev)-1); > > > > I guess size-1 is to give room for terminating null byte, but for this > > case is it guarantied that pt->rx_dev last byte is NULL? > > > > > > > -- > In the beginning was the lambda, and the lambda was with Emacs, and Emacs > was the lambda.