From 710cab6f675a2dbad2cdad6942aa379db5d7a508 Mon Sep 17 00:00:00 2001 From: Remy Horton Date: Thu, 11 May 2017 13:53:30 +0100 Subject: [PATCH] metrics: fix out of bound access Fixes memory access errors detected by Coverity. All cases are the maximum permissable value causing an out-by-one overrun. Coverity issue: 143433, 143434, 143460, 143464 Fixes: 349950ddb9c5 ("metrics: add information metrics library") Signed-off-by: Remy Horton --- lib/librte_metrics/rte_metrics.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index e9a122c1fb..6e61f9b1ba 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -51,7 +51,7 @@ */ struct rte_metrics_meta_s { /** Name of metric */ - char name[RTE_METRICS_MAX_NAME_LEN]; + char name[RTE_METRICS_MAX_NAME_LEN + 1]; /** Current value for metric */ uint64_t value[RTE_MAX_ETHPORTS]; /** Used for global metrics */ @@ -176,7 +176,7 @@ rte_metrics_update_values(int port_id, uint16_t cnt_setsize; if (port_id != RTE_METRICS_GLOBAL && - (port_id < 0 || port_id > RTE_MAX_ETHPORTS)) + (port_id < 0 || port_id >= RTE_MAX_ETHPORTS)) return -EINVAL; if (values == NULL) @@ -263,7 +263,7 @@ rte_metrics_get_values(int port_id, int return_value; if (port_id != RTE_METRICS_GLOBAL && - (port_id < 0 || port_id > RTE_MAX_ETHPORTS)) + (port_id < 0 || port_id >= RTE_MAX_ETHPORTS)) return -EINVAL; memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME); -- 2.20.1