[dpdk-dev,v6,15/16] app/test-bbdev: strcpy ok for allocated string

Message ID 152627406736.52758.1036851396439121779.stgit@localhost.localdomain (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

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

Commit Message

Andy Green May 14, 2018, 5:01 a.m. UTC
  Signed-off-by: Andy Green <andy@warmcat.com>
Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org
---
 app/test-bbdev/test_bbdev_vector.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ferruh Yigit May 14, 2018, 8:42 p.m. UTC | #1
On 5/14/2018 6:01 AM, Andy Green wrote:
> Signed-off-by: Andy Green <andy@warmcat.com>
> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
> Cc: stable@dpdk.org
> ---
>  app/test-bbdev/test_bbdev_vector.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
> index a37e35f4d..c574f2135 100644
> --- a/app/test-bbdev/test_bbdev_vector.c
> +++ b/app/test-bbdev/test_bbdev_vector.c
> @@ -892,7 +892,7 @@ test_bbdev_vector_read(const char *filename,
>  		}
>  
>  		memset(entry, 0, strlen(line) + 1);
> -		strncpy(entry, line, strlen(line));
> +		strcpy(entry, line);

agreed that according above code strcpy is OK but still why change it? Is this
fixing a build error?

>  
>  		/* check if entry ends with , or = */
>  		if (entry[strlen(entry) - 1] == ','
>
  
Ferruh Yigit May 14, 2018, 8:56 p.m. UTC | #2
On 5/14/2018 9:42 PM, Ferruh Yigit wrote:
> On 5/14/2018 6:01 AM, Andy Green wrote:
>> Signed-off-by: Andy Green <andy@warmcat.com>
>> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
>> Cc: stable@dpdk.org
>> ---
>>  app/test-bbdev/test_bbdev_vector.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
>> index a37e35f4d..c574f2135 100644
>> --- a/app/test-bbdev/test_bbdev_vector.c
>> +++ b/app/test-bbdev/test_bbdev_vector.c
>> @@ -892,7 +892,7 @@ test_bbdev_vector_read(const char *filename,
>>  		}
>>  
>>  		memset(entry, 0, strlen(line) + 1);
>> -		strncpy(entry, line, strlen(line));
>> +		strcpy(entry, line);
> 
> agreed that according above code strcpy is OK but still why change it? Is this
> fixing a build error?

Yes:

.../app/test-bbdev/test_bbdev_vector.c:895:3: error: ‘strncpy’ output truncated
before terminating nul copying as many bytes from a string as its length
[-Werror=stringop-truncation]
   strncpy(entry, line, strlen(line));
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> 
>>  
>>  		/* check if entry ends with , or = */
>>  		if (entry[strlen(entry) - 1] == ','
>>
>
  
Ferruh Yigit May 14, 2018, 9:01 p.m. UTC | #3
On 5/14/2018 9:56 PM, Ferruh Yigit wrote:
> On 5/14/2018 9:42 PM, Ferruh Yigit wrote:
>> On 5/14/2018 6:01 AM, Andy Green wrote:

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

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

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>


>>> ---
>>>  app/test-bbdev/test_bbdev_vector.c |    2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
>>> index a37e35f4d..c574f2135 100644
>>> --- a/app/test-bbdev/test_bbdev_vector.c
>>> +++ b/app/test-bbdev/test_bbdev_vector.c
>>> @@ -892,7 +892,7 @@ test_bbdev_vector_read(const char *filename,
>>>  		}
>>>  
>>>  		memset(entry, 0, strlen(line) + 1);
>>> -		strncpy(entry, line, strlen(line));
>>> +		strcpy(entry, line);
>>
>> agreed that according above code strcpy is OK but still why change it? Is this
>> fixing a build error?
> 
> Yes:
> 
> .../app/test-bbdev/test_bbdev_vector.c:895:3: error: ‘strncpy’ output truncated
> before terminating nul copying as many bytes from a string as its length
> [-Werror=stringop-truncation]
>    strncpy(entry, line, strlen(line));
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
>>
>>>  
>>>  		/* check if entry ends with , or = */
>>>  		if (entry[strlen(entry) - 1] == ','
>>>
>>
>
  

Patch

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index a37e35f4d..c574f2135 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -892,7 +892,7 @@  test_bbdev_vector_read(const char *filename,
 		}
 
 		memset(entry, 0, strlen(line) + 1);
-		strncpy(entry, line, strlen(line));
+		strcpy(entry, line);
 
 		/* check if entry ends with , or = */
 		if (entry[strlen(entry) - 1] == ','