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 <remy.horton@intel.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Remy Horton 2018-07-06 14:21:19 +01:00 committed by Thomas Monjalon
parent 90b0e5aaf4
commit 50d2459fdd

View File

@ -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) {