From: Remy Horton Date: Fri, 6 Jul 2018 13:21:19 +0000 (+0100) Subject: metrics: add check for invalid key X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=50d2459fdde1916c2ebce1a3751ab2fa59c0766f;p=dpdk.git metrics: add check for invalid key This patchset adds a check to rte_metrics_update_values() that prevents the updating of metrics when presented with an invalid metric key. Previously, doing the latter could result in a crash. Fixes: 349950ddb9c5 ("metrics: add information metrics library") Cc: stable@dpdk.org Signed-off-by: Remy Horton Acked-by: Ferruh Yigit --- diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 258f0582c3..b5638f553d 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -159,6 +159,11 @@ rte_metrics_update_values(int port_id, stats = memzone->addr; rte_spinlock_lock(&stats->lock); + + if (key >= stats->cnt_stats) { + rte_spinlock_unlock(&stats->lock); + return -EINVAL; + } idx_metric = key; cnt_setsize = 1; while (idx_metric < stats->cnt_stats) {