[v2] test/distributor: fix sprintf with strlcpy

Message ID 1550137549-5184-1-git-send-email-pallantlax.poornima@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] test/distributor: fix sprintf with strlcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Poornima, PallantlaX Feb. 14, 2019, 9:45 a.m. UTC
  sprintf function is not secure as it doesn't check the length of string.
replaced sprintf with strlcpy.

Fixes: f74df2c57e ("test/distributor: test single and burst API")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
v2: Addressed review comment to replace snprintf to strlcpy.
---

 test/test/test_distributor.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Hunt, David March 25, 2019, 3:11 p.m. UTC | #1
Hi Poornima,


On 14/2/2019 9:45 AM, Pallantla Poornima wrote:
> sprintf function is not secure as it doesn't check the length of string.
> replaced sprintf with strlcpy.
>
> Fixes: f74df2c57e ("test/distributor: test single and burst API")
> Cc: stable@dpdk.org
>
> Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> ---
> v2: Addressed review comment to replace snprintf to strlcpy.
> ---
>
>   test/test/test_distributor.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/test/test/test_distributor.c b/test/test/test_distributor.c
> index 98919ec0c..da3348fd1 100644
> --- a/test/test/test_distributor.c
> +++ b/test/test/test_distributor.c
> @@ -11,6 +11,7 @@
>   #include <rte_mempool.h>
>   #include <rte_mbuf.h>
>   #include <rte_distributor.h>
> +#include <rte_string_fns.h>
>   
>   #define ITER_POWER 20 /* log 2 of how many iterations we do when timing. */
>   #define BURST 32
> @@ -642,9 +643,11 @@ test_distributor(void)
>   
>   		worker_params.dist = dist[i];
>   		if (i)
> -			sprintf(worker_params.name, "burst");
> +			strlcpy(worker_params.name, "burst",
> +					sizeof(worker_params.name));
>   		else
> -			sprintf(worker_params.name, "single");
> +			strlcpy(worker_params.name, "single",
> +					sizeof(worker_params.name));
>   
>   		rte_eal_mp_remote_launch(handle_work,
>   				&worker_params, SKIP_MASTER);


Acked-by: David Hunt <david.hunt@intel.com>
  
Thomas Monjalon April 4, 2019, 11:55 p.m. UTC | #2
25/03/2019 16:11, Hunt, David:
> On 14/2/2019 9:45 AM, Pallantla Poornima wrote:
> > sprintf function is not secure as it doesn't check the length of string.
> > replaced sprintf with strlcpy.
> >
> > Fixes: f74df2c57e ("test/distributor: test single and burst API")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
> > ---
> > v2: Addressed review comment to replace snprintf to strlcpy.
> > ---
> 
> Acked-by: David Hunt <david.hunt@intel.com>

Applied, thanks
  

Patch

diff --git a/test/test/test_distributor.c b/test/test/test_distributor.c
index 98919ec0c..da3348fd1 100644
--- a/test/test/test_distributor.c
+++ b/test/test/test_distributor.c
@@ -11,6 +11,7 @@ 
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_distributor.h>
+#include <rte_string_fns.h>
 
 #define ITER_POWER 20 /* log 2 of how many iterations we do when timing. */
 #define BURST 32
@@ -642,9 +643,11 @@  test_distributor(void)
 
 		worker_params.dist = dist[i];
 		if (i)
-			sprintf(worker_params.name, "burst");
+			strlcpy(worker_params.name, "burst",
+					sizeof(worker_params.name));
 		else
-			sprintf(worker_params.name, "single");
+			strlcpy(worker_params.name, "single",
+					sizeof(worker_params.name));
 
 		rte_eal_mp_remote_launch(handle_work,
 				&worker_params, SKIP_MASTER);