Thread (41 messages) 41 messages, 6 authors, 2016-06-27

Re: [PATCH 3/3] app/pdump: fix string overflow

From: Pattan, Reshma <hidden>
Date: 2016-06-22 09:24:38

Hi,
-----Original Message-----
From: Richardson, Bruce
Sent: Wednesday, June 22, 2016 10:22 AM
To: Anupam Kapoor <redacted>
Cc: Yigit, Ferruh <redacted>; Pattan, Reshma
[off-list ref]; dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH 3/3] app/pdump: fix string overflow

On Wed, Jun 22, 2016 at 12:16:27PM +0530, Anupam Kapoor wrote:
quoted
quoted
      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.
Ok, will make the changes.

Thanks,
Reshma
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help