DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Anupam Kapoor <anupam.kapoor@gmail.com>
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
	Reshma Pattan <reshma.pattan@intel.com>,
	dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH 3/3] app/pdump: fix string overflow
Date: Wed, 22 Jun 2016 10:21:30 +0100	[thread overview]
Message-ID: <20160622092130.GB9728@bricha3-MOBL3> (raw)
In-Reply-To: <CAEXHiZEzC_zv9tOro=XiYbUoh_0Os6ZH9wn-M997exn2t-kzbw@mail.gmail.com>

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 <ferruh.yigit@intel.com>
> 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 <reshma.pattan@intel.com>
> > > ---
> > >  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.

  reply	other threads:[~2016-06-22  9:21 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-21 15:18 [dpdk-dev] [PATCH 0/3] fix coverity issues in packet capture framework Reshma Pattan
2016-06-21 15:18 ` [dpdk-dev] [PATCH 1/3] pdump: check getenv return value Reshma Pattan
2016-06-21 16:55   ` Ferruh Yigit
2016-06-22  8:01     ` Pattan, Reshma
2016-06-21 15:18 ` [dpdk-dev] [PATCH 2/3] pdump: fix string overflow Reshma Pattan
2016-06-21 17:14   ` Ferruh Yigit
2016-06-21 15:18 ` [dpdk-dev] [PATCH 3/3] app/pdump: " Reshma Pattan
2016-06-21 17:21   ` Ferruh Yigit
2016-06-22  6:46     ` Anupam Kapoor
2016-06-22  9:21       ` Bruce Richardson [this message]
2016-06-22  9:24         ` Pattan, Reshma
2016-06-22 14:07 ` [dpdk-dev] [PATCH v2 0/3] fix coverity issues in packet capture framework Reshma Pattan
2016-06-22 14:07   ` [dpdk-dev] [PATCH v2 1/3] pdump: check getenv return value Reshma Pattan
2016-06-22 14:07   ` [dpdk-dev] [PATCH v2 2/3] pdump: fix string overflow Reshma Pattan
2016-06-22 14:07   ` [dpdk-dev] [PATCH v2 3/3] app/pdump: " Reshma Pattan
2016-06-23 14:36   ` [dpdk-dev] [PATCH v3 0/4] fix issues in packet capture framework Reshma Pattan
2016-06-23 14:36     ` [dpdk-dev] [PATCH v3 1/4] pdump: fix default socket path Reshma Pattan
2016-06-23 14:36     ` [dpdk-dev] [PATCH v3 2/4] pdump: check getenv return value Reshma Pattan
2016-06-23 14:36     ` [dpdk-dev] [PATCH v3 3/4] pdump: fix string overflow Reshma Pattan
2016-06-23 14:36     ` [dpdk-dev] [PATCH v3 4/4] app/pdump: " Reshma Pattan
2016-06-24 13:54     ` [dpdk-dev] [PATCH v4 0/5] fix issues in packet capture framework Reshma Pattan
2016-06-24 13:54       ` [dpdk-dev] [PATCH v4 1/5] pdump: fix default socket path Reshma Pattan
2016-06-24 14:54         ` Thomas Monjalon
2016-06-24 15:05           ` Pattan, Reshma
2016-06-24 16:39           ` Pattan, Reshma
2016-06-24 13:54       ` [dpdk-dev] [PATCH v4 2/5] pdump: check getenv return value Reshma Pattan
2016-06-24 13:54       ` [dpdk-dev] [PATCH v4 3/5] pdump: fix string overflow Reshma Pattan
2016-06-24 13:54       ` [dpdk-dev] [PATCH v4 4/5] app/pdump: " Reshma Pattan
2016-06-24 13:54       ` [dpdk-dev] [PATCH v4 5/5] app/pdump: fix type casting of ring size Reshma Pattan
2016-06-24 16:36       ` [dpdk-dev] [PATCH v5 0/5] fix issues in packet capture framework Reshma Pattan
2016-06-24 16:36         ` [dpdk-dev] [PATCH v5 1/5] pdump: fix default socket path Reshma Pattan
2016-06-24 22:50           ` Mcnamara, John
2016-06-24 16:36         ` [dpdk-dev] [PATCH v5 2/5] pdump: check getenv return value Reshma Pattan
2016-06-24 22:50           ` Mcnamara, John
2016-06-24 16:36         ` [dpdk-dev] [PATCH v5 3/5] pdump: fix string overflow Reshma Pattan
2016-06-24 22:51           ` Mcnamara, John
2016-06-24 16:36         ` [dpdk-dev] [PATCH v5 4/5] app/pdump: " Reshma Pattan
2016-06-24 22:51           ` Mcnamara, John
2016-06-24 16:36         ` [dpdk-dev] [PATCH v5 5/5] app/pdump: fix type casting of ring size Reshma Pattan
2016-06-24 22:51           ` Mcnamara, John
2016-06-27 14:50         ` [dpdk-dev] [PATCH v5 0/5] fix issues in packet capture framework Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160622092130.GB9728@bricha3-MOBL3 \
    --to=bruce.richardson@intel.com \
    --cc=anupam.kapoor@gmail.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=reshma.pattan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).