From: David Marchand Date: Sat, 15 Jun 2019 06:42:22 +0000 (+0200) Subject: test/latency: fix stack smashing X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=1ec35c80e873c3cd8325705d3515751c8f3367c0;p=dpdk.git test/latency: fix stack smashing Caught in one Travis run: + ------------------------------------------------------- + + Test Suite : Latency Stats Unit Test Suite + ------------------------------------------------------- + + TestCase [ 0] : test_latency_init succeeded + TestCase [ 1] : test_latency_update succeeded [snip] + TestCase [1601724781] : test_latencystats_get_names succeeded [snip] + Tests Failed : 1601790830 htonl(1601724781) -> "m", "a", "x", "_" htonl(1601790830) -> "n", "c", "y", "_" Looks like someone went too far. The test passes a bigger size than the array it passes along. Fixes: 1e3676a06e4c ("test/latency: add unit tests for latencystats library") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Aaron Conole --- diff --git a/app/test/test_latencystats.c b/app/test/test_latencystats.c index 039c508cd1..8dd794be46 100644 --- a/app/test/test_latencystats.c +++ b/app/test/test_latencystats.c @@ -69,13 +69,10 @@ static int test_latencystats_get_names(void) int ret = 0, i = 0; int size = 0; struct rte_metric_name names[NUM_STATS]; - struct rte_metric_name wrongnames[NUM_STATS - 2]; size_t m_size = sizeof(struct rte_metric_name); for (i = 0; i < NUM_STATS; i++) memset(&names[i], 0, m_size); - for (i = 0; i < NUM_STATS - 2; i++) - memset(&wrongnames[i], 0, m_size); /* Success Test: Valid names and size */ size = NUM_STATS; @@ -99,10 +96,6 @@ static int test_latencystats_get_names(void) TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the metrics count," "Actual: %d Expected: %d", ret, NUM_STATS); - /* Failure Test: Invalid names (array size lesser than size) */ - size = NUM_STATS + 1; - ret = rte_latencystats_get_names(wrongnames, size); - TEST_ASSERT((ret == NUM_STATS), "Test Failed to get metrics names"); return TEST_SUCCESS; } @@ -112,13 +105,10 @@ static int test_latencystats_get(void) int ret = 0, i = 0; int size = 0; struct rte_metric_value values[NUM_STATS]; - struct rte_metric_value wrongvalues[NUM_STATS - 2]; size_t v_size = sizeof(struct rte_metric_value); for (i = 0; i < NUM_STATS; i++) memset(&values[i], 0, v_size); - for (i = 0; i < NUM_STATS - 2; i++) - memset(&wrongvalues[i], 0, v_size); /* Success Test: Valid values and valid size */ size = NUM_STATS; @@ -137,14 +127,6 @@ static int test_latencystats_get(void) TEST_ASSERT((ret == NUM_STATS), "Test Failed to get the stats count," "Actual: %d Expected: %d", ret, NUM_STATS); - /* Failure Test: Invalid values(array size lesser than size) - * and invalid size - */ - size = NUM_STATS + 2; - ret = rte_latencystats_get(wrongvalues, size); - TEST_ASSERT(ret == NUM_STATS, "Test Failed to get latency metrics" - " values"); - return TEST_SUCCESS; }