[dpdk-dev,v4,18/18] app/test-bbdev: strcpy ok for allocated string

Message ID 152600320633.53146.1883908043976158624.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 11, 2018, 1:46 a.m. UTC
  Signed-off-by: Andy Green <andy@warmcat.com>
---
 app/test-bbdev/test_bbdev_vector.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

De Lara Guarch, Pablo May 11, 2018, 1:02 p.m. UTC | #1
> -----Original Message-----

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Andy Green

> Sent: Friday, May 11, 2018 2:47 AM

> To: dev@dpdk.org

> Subject: [dpdk-dev] [PATCH v4 18/18] app/test-bbdev: strcpy ok for allocated

> string

> 

> Signed-off-by: Andy Green <andy@warmcat.com>

> ---

>  app/test-bbdev/test_bbdev_vector.c |    3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-

> bbdev/test_bbdev_vector.c

> index c574f2135..4a3ddcffe 100644

> --- a/app/test-bbdev/test_bbdev_vector.c

> +++ b/app/test-bbdev/test_bbdev_vector.c

> @@ -914,7 +914,8 @@ test_bbdev_vector_read(const char *filename,

>  				}

> 

>  				entry = entry_extended;

> -				strncat(entry, line, strlen(line));

> +				/* entry has been allocated accordingly */

> +				strcpy(&entry[strlen(entry)], line);


If memset is removed in the previous patch, then we'll need to use strlcpy
here, to ensure NULL termination.

Missing fixes line and CC stable:

Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org
  
Andy Green May 12, 2018, 1:39 a.m. UTC | #2
On 05/11/2018 09:02 PM, De Lara Guarch, Pablo wrote:
> 
> 
>> -----Original Message-----
>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Andy Green
>> Sent: Friday, May 11, 2018 2:47 AM
>> To: dev@dpdk.org
>> Subject: [dpdk-dev] [PATCH v4 18/18] app/test-bbdev: strcpy ok for allocated
>> string
>>
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> ---
>>   app/test-bbdev/test_bbdev_vector.c |    3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-
>> bbdev/test_bbdev_vector.c
>> index c574f2135..4a3ddcffe 100644
>> --- a/app/test-bbdev/test_bbdev_vector.c
>> +++ b/app/test-bbdev/test_bbdev_vector.c
>> @@ -914,7 +914,8 @@ test_bbdev_vector_read(const char *filename,
>>   				}
>>
>>   				entry = entry_extended;
>> -				strncat(entry, line, strlen(line));
>> +				/* entry has been allocated accordingly */
>> +				strcpy(&entry[strlen(entry)], line);
> 
> If memset is removed in the previous patch, then we'll need to use strlcpy
> here, to ensure NULL termination.

No... the destination has been allocated dynamically so there is no case 
where the source length can exceed the destination.

I think for that reason it's OK to remove the memset() here, because for 
the same reason it will always exactly fill the dynamically sized string 
anyway.

-Andy

> Missing fixes line and CC stable:
> 
> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
> Cc: stable@dpdk.org
>
  

Patch

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index c574f2135..4a3ddcffe 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -914,7 +914,8 @@  test_bbdev_vector_read(const char *filename,
 				}
 
 				entry = entry_extended;
-				strncat(entry, line, strlen(line));
+				/* entry has been allocated accordingly */
+				strcpy(&entry[strlen(entry)], line);
 
 				if (entry[strlen(entry) - 1] != ',')
 					break;