From b7167593e09e67b4746d87ecc390ffff8809599b Mon Sep 17 00:00:00 2001 From: Pablo de Lara Date: Mon, 16 Jul 2018 07:26:27 +0100 Subject: [PATCH] devargs: fix build with gcc 4.7 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixed possible out-of-bounds issue: lib/librte_eal/common/eal_common_devargs.c: In function ‘rte_devargs_layers_parse’: lib/librte_eal/common/eal_common_devargs.c:121:7: error: array subscript is above array bounds Bugzilla ID: 71 Fixes: 338327d731e6 ("devargs: add function to parse device layers") Signed-off-by: Pablo de Lara Acked-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_devargs.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index a22a2002ed..1a7b00ece8 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -118,12 +118,17 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, } while (s != NULL) { - if (strncmp(layers[i].key, s, - strlen(layers[i].key)) && - /* The last layer is free-form. - * The "driver" key is not required (but accepted). - */ - i != RTE_DIM(layers) - 1) + if (i >= RTE_DIM(layers)) { + RTE_LOG(ERR, EAL, "Unrecognized layer %s\n", s); + ret = -EINVAL; + goto get_out; + } + /* + * The last layer is free-form. + * The "driver" key is not required (but accepted). + */ + if (strncmp(layers[i].key, s, strlen(layers[i].key)) && + i != RTE_DIM(layers) - 1) goto next_layer; layers[i].str = s; layers[i].kvlist = rte_kvargs_parse_delim(s, NULL, "/"); @@ -136,11 +141,6 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, if (s != NULL) s++; next_layer: - if (i >= RTE_DIM(layers)) { - RTE_LOG(ERR, EAL, "Unrecognized layer %s\n", s); - ret = -EINVAL; - goto get_out; - } i++; } -- 2.20.1