[v2] hash: fix sprintf with snprintf

Message ID 1550149062-14300-1-git-send-email-pallantlax.poornima@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] hash: fix sprintf with snprintf |

Checks

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

Commit Message

Poornima, PallantlaX Feb. 14, 2019, 12:57 p.m. UTC
  sprintf function is not secure as it doesn't check the length of string.
More secure function snprintf is used.

Fixes: 473d1bebce ("hash: allow to store data in hash table")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
v2: Addressed review comment to correct the format specifier of 
hastest_key_lens.
---

 test/test/test_hash_perf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Wang, Yipeng1 March 25, 2019, 6:05 p.m. UTC | #1
Sorry for the late reply, but I noticed the test folder is recently moved under app so you may need a rebase.

Please keep my ack after rebase:  Acked-by: Yipeng Wang <yipeng1.wang at intel.com>

>-----Original Message-----
>From: Poornima, PallantlaX
>Sent: Monday, March 25, 2019 7:43 AM
>To: dev@dpdk.org
>Cc: Pattan, Reshma <reshma.pattan@intel.com>; Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh
><sameh.gobriel@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>; De Lara Guarch, Pablo
><pablo.de.lara.guarch@intel.com>; stephen@networkplumber.org; stable@dpdk.org
>Subject: RE: [PATCH v2] hash: fix sprintf with snprintf
>
>Hi,
>
>>-----Original Message-----
>>From: Poornima, PallantlaX
>>Sent: Thursday, February 14, 2019 6:28 PM
>>To: dev@dpdk.org
>>Cc: Pattan, Reshma <reshma.pattan@intel.com>; Wang, Yipeng1
>><yipeng1.wang@intel.com>; Gobriel, Sameh <sameh.gobriel@intel.com>;
>>Richardson, Bruce <bruce.richardson@intel.com>; De Lara Guarch, Pablo
>><pablo.de.lara.guarch@intel.com>; stephen@networkplumber.org;
>>Poornima, PallantlaX <pallantlax.poornima@intel.com>; stable@dpdk.org
>>Subject: [PATCH v2] hash: fix sprintf with snprintf
>>
>>sprintf function is not secure as it doesn't check the length of string.
>>More secure function snprintf is used.
>>
>>Fixes: 473d1bebce ("hash: allow to store data in hash table")
>>Cc: stable@dpdk.org
>>
>>Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
>>---
>>v2: Addressed review comment to correct the format specifier of
>>hastest_key_lens.
>>---
>
>
>Request for ACK please if there are no comments
>
>Regards,
>Poornima
  

Patch

diff --git a/test/test/test_hash_perf.c b/test/test/test_hash_perf.c
index 525211180..5648fce02 100644
--- a/test/test/test_hash_perf.c
+++ b/test/test/test_hash_perf.c
@@ -85,9 +85,11 @@  create_table(unsigned int with_data, unsigned int table_index,
 
 	if (with_data)
 		/* Table will store 8-byte data */
-		sprintf(name, "test_hash%d_data", hashtest_key_lens[table_index]);
+		snprintf(name, sizeof(name), "test_hash%u_data",
+				hashtest_key_lens[table_index]);
 	else
-		sprintf(name, "test_hash%d", hashtest_key_lens[table_index]);
+		snprintf(name, sizeof(name), "test_hash%u",
+				hashtest_key_lens[table_index]);
 
 
 	if (with_locks)