table: fix out of bounds write

Message ID 20210407105953.18113-1-cristian.dumitrescu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series table: fix out of bounds write |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Cristian Dumitrescu April 7, 2021, 10:59 a.m. UTC
  Fix out of bounds write. The allocated string size was incorrect.

Coverity issue: 369670
Fixes: 66440b7b22f2 ("table: add wildcard match table type")

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
 lib/librte_table/rte_swx_table_wm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
  

Comments

Thomas Monjalon April 19, 2021, 5:51 p.m. UTC | #1
07/04/2021 12:59, Cristian Dumitrescu:
> Fix out of bounds write. The allocated string size was incorrect.
> 
> Coverity issue: 369670
> Fixes: 66440b7b22f2 ("table: add wildcard match table type")
> 
> Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_table/rte_swx_table_wm.c b/lib/librte_table/rte_swx_table_wm.c
index 9924231b3..e260be106 100644
--- a/lib/librte_table/rte_swx_table_wm.c
+++ b/lib/librte_table/rte_swx_table_wm.c
@@ -53,15 +53,14 @@  env_free(void *start, size_t size)
 
 static char *get_unique_name(void)
 {
-	char *name;
-	uint64_t *tsc;
+	uint64_t tsc = rte_get_tsc_cycles();
+	size_t size = sizeof(uint64_t) * 2 + 1;
+	char *name = calloc(1, size);
 
-	name = calloc(7, 1);
 	if (!name)
 		return NULL;
 
-	tsc = (uint64_t *) name;
-	*tsc = rte_get_tsc_cycles();
+	snprintf(name, size, "%016" PRIx64, tsc);
 	return name;
 }